Search code examples
cookiescherrypy

Delete cookies in cherrypy


I am trying to delete or expire cookies in Cherrypy, but it does not seem to be working. this is how I try:

cookie[mykey]['expires'] = 0
cherrypy.request.cookie.clear()

After executing these lines of code, I still can see cookies and read them


Solution

  • According to official cherrypy document, in order to expire cookies in cherrypy, we need to re-create them in response and set expiry date and max-age

        cherrypy.response.cookie[key] = ''
        cherrypy.response.cookie[key]['expires'] = 0
        cherrypy.response.cookie[key]['max-age'] = 0 
    

    I was altering cherrypy.request.cookie which will not have any effect on the cookies.