Currently, http.cookiejar only supports path-like objects for FileCookieJar and its sub-classes (MozillaCookieJar and LWPCookieJar). So there’s no clean way to load interoperable cookie format data other than from the disk.
Reasoning:
- Cookie files can contain sensitive info, so you may not want to write it to disk.
- Its useful to provide the user other options to load data, other than from the disk, especially with keys/“secrets” (which cookies can contain). E.g. environment variable or standard input.
- As I understand it, its preferable for python libraries to support file-like objects rather than just paths, when the path itself is not relevant (as in this case - http.cookiejar only uses for error messages for failing to load the path).
Workarounds:
- Using the private function
_really_load(not desirable as its a private function) - Making a fork of http.cookiejar (not desirable as it requires maintenance and this appears to require a small change to the http.cookiejar code)