itzhaki
itzhaki

Reputation: 840

Clearing a cookie with SimpleCookie

I'm trying to clear a cookie

I read the correct way to do so is to set the 'expires' field to a past time

But when trying to do so using the SimpleCookie library I get the following exception:

Attempt to set a reserved key: expires

What's the right way to handle it then?

Upvotes: 1

Views: 1926

Answers (1)

Jeffrey Tang
Jeffrey Tang

Reputation: 793

import os
import http.cookies

c = http.cookies.SimpleCookie(os.environ.get('HTTP_COOKIE'))
c['hello'] = 'world'
c['hello']['expires'] = 'Thu, 01 Jan 1970 00:00:00 GMT'
print(c)

You have to set the expires field as part of a cookie. Output:

Set-Cookie: hello=world; expires=Thu, 01 Jan 1970 00:00:00 GMT

Upvotes: 2

Related Questions