How to set cookie expiry?
See original GitHub issueHi all,
I’m hitting what seems to be a super straightforward problem, but… how does one set a cookie expiry?
I have something similar to this right now:
responses.add(
responses.POST,
url,
status=200,
adding_headers={
'Set-Cookie': (
'sessionid=c83dc7dc-e0b9-xxxx-xxxx-xxxxxxxxxxxx; '
'expires=Wed, 29 Aug 2018 15:23:46 GMT;'
),
}
)
Relevant traceback portion:
.tox/py36/lib/python3.6/site-packages/responses.py:572: in unbound_on_send
return self._on_request(adapter, request, *a, **kwargs)
.tox/py36/lib/python3.6/site-packages/responses.py:559: in _on_request
resp_cookies = Cookies.from_request(response.headers['set-cookie'])
.tox/py36/lib/python3.6/site-packages/cookies.py:1113: in from_request
header_data, ignore_bad_cookies=ignore_bad_cookies)
.tox/py36/lib/python3.6/site-packages/cookies.py:1043: in parse_request
header_data, ignore_bad_cookies=ignore_bad_cookies)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
header_data = 'sessionid=c83dc7dc-e0b9-xxxx-xxxx-xxxxxxxxxxxx; Expires=Wed, 14 Aug 2019 16:18:18 GMT'
ignore_bad_cookies = False
def _parse_request(header_data, ignore_bad_cookies=False):
"""Turn one or more lines of 'Cookie:' header data into a dict mapping
cookie names to cookie values (raw strings).
"""
cookies_dict = {}
for line in Definitions.EOL.split(header_data.strip()):
matches = Definitions.COOKIE_RE.finditer(line)
matches = [item for item in matches]
for match in matches:
invalid = match.group('invalid')
if invalid:
if not ignore_bad_cookies:
> raise InvalidCookieError(data=invalid)
E cookies.InvalidCookieError: '' ' Expires=Wed, 14 Aug 2019 16:18:18 GMT'
.tox/py36/lib/python3.6/site-packages/cookies.py:598: InvalidCookieError
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
How can I set a cookie with expire time? - Stack Overflow
By using max-age: Creating the cookie: document.cookie = "cookieName=cookieValue; max-age=86400; path=/;";. Deleting the cookie: document. · By using expires:.
Read more >Set-Cookie - HTTP - MDN Web Docs
Indicates the number of seconds until the cookie expires. A zero or negative number will expire the cookie immediately. If both Expires and...
Read more >How to Set Cookie and Update Cookie with JavaScript - Tabnine
Set an expiration date for a cookie. By default, cookies will be automatically deleted once the browser is closed. This prevents users from...
Read more >How to set cookies to expire in 1 hour in JavaScript?
You can extend the life of a cookie beyond the current browser session by setting an expiration date and saving the expiry date...
Read more >How to set up a cookie that never expires in JavaScript
document.cookie = "cookieName= true; expires=Tue, 19 Jan 2038 04:14:07 GMT"; // OR const cookieName = "something" ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@fxfitz then you can considering close the issue
I’m sorry, but I’m no longer working on this problem set, and I do not have time to re-verify the expected behavior.