Replies: 1 comment
|
HTTPX's Python API can persist cookies, but the command-line client does not currently expose a Netscape cookie-jar/file option. For automation, use a small Python wrapper with a persistent cookie jar. HTTPX's Cookies object is compatible with Python's cookiejar model for requests, while MozillaCookieJar can load/save Netscape-format files: Be careful with assumptions about “never expires”: a server can invalidate/rotate an access token independently of cookie expiry, and HttpOnly/SameSite/domain/path rules still apply. Browser cookie databases are not Netscape files and may be encrypted; exporting them is a separate, security-sensitive step. A future --cookie-file CLI flag should define load/save timing, session-cookie handling, file locking, permissions, and whether it overwrites the file after redirects. Until then, the Python API is the appropriate place for stateful authenticated automation; the httpx CLI is intentionally a lightweight request tool. |
Uh oh!
There was an error while loading. Please reload this page.
This is very important for automation use cases.
So imagine I want to send a POST request to an authenticated endpoint. I need to include a certain cookie with an ACCESS_TOKEN
You can do it manually but that ACCESS_TOKEN will expire and need to be updated again after fetching it again from the browser.
With a netscape style cookie file passed in as
--cookie-file, the httpx library can update the new cookies received from every request and the cookie file acts as a cookie jar.This feature works great in
yt-dlpand the login cookies passed in never expires because it is being updated by yt-dlp.All reactions