Skip to content
This repository has been archived by the owner on Jan 3, 2024. It is now read-only.

Error handling request in HAR with large timestamp in cookie #730

Open
LightBit opened this issue Dec 7, 2023 · 0 comments
Open

Error handling request in HAR with large timestamp in cookie #730

LightBit opened this issue Dec 7, 2023 · 0 comments

Comments

@LightBit
Copy link

LightBit commented Dec 7, 2023

When cookie has expiration time set to 9999-12-31T23:59:59+00:00, I get exception OSError Invalid argument on Windows:

Error handling request
Traceback (most recent call last):
  File "C:\Python\Lib\site-packages\seleniumwire\handler.py", line 133, in response
    self.proxy.storage.save_har_entry(flow.request.id, har.create_har_entry(flow))
                                                       ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python\Lib\site-packages\seleniumwire\har.py", line 85, in create_har_entry
    "cookies": _format_response_cookies(flow.response.cookies.fields),
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python\Lib\site-packages\seleniumwire\har.py", line 154, in _format_response_cookies
    return _format_cookies((c[0], c[1][0], c[1][1]) for c in fields)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python\Lib\site-packages\seleniumwire\har.py", line 142, in _format_cookies
    cookie_har["expires"] = datetime.fromtimestamp(expire_ts, timezone.utc).isoformat()
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
OSError: [Errno 22] Invalid argument

datetime.fromtimestamp() on Windows does not work with large timestamps like 253402300799.

Workaround is to use timedelta:

expire = datetime(1970, 1, 1, tzinfo=timezone.utc) + timedelta(seconds=expire_ts)
cookie_har["expires"] = expire.isoformat()
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant