question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to set cookie expiry?

See original GitHub issue

Hi 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:closed
  • Created 5 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
beliaev-maksimcommented, Nov 24, 2021

@fxfitz then you can considering close the issue

0reactions
fxfitzcommented, Nov 24, 2021

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found