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

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

Description

@LightBit

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()

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions