3 min read

Load httpx cookies from a Netscape cookies.txt

httpx does not read cookies.txt itself; convert your export to Netscape here, load it with MozillaCookieJar, and pass the cookies into httpx.Client(cookies=...).

The unique step is the bridge: httpx’s Cookies object wants name/value/domain, not a file path. This converter produces the file; the snippet below loads it.

httpx cookieshttpx cookies.txthttpx CookieJarhttpx Netscape
  1. 1
    Export JSON from Chrome

    CookieMan JSON Array for the host httpx will call.

  2. 2
    Convert to Netscape

    Paste and download cookies.txt. Check domains match the URL you will request.

  3. 3
    Load into httpx

    Run the snippet. Confirm client.cookies lists the names before the first request.

Cookies are credentials. Conversion stays in this page — delete the file when you are done.

Working httpx snippet

            from http.cookiejar import MozillaCookieJar
import httpx

jar = MozillaCookieJar("cookies.txt")
jar.load(ignore_discard=True, ignore_expires=True)

client = httpx.Client()
for c in jar:
    client.cookies.set(c.name, c.value, domain=c.domain, path=c.path)

response = client.get("https://example.com/dashboard")
print(response.status_code)
client.close()
          
httpx will not send a cookie whose domain does not match the request URL. If the jar still says localhost, you converted a header string — fix domains in JSON first.

httpx versus Requests on the same file

ClientLoad Netscape directly?Typical path
RequestsYes, assign MozillaCookieJar to session.cookiesOne assignment
httpxNo file APIIterate the jar into client.cookies.set

Questions people ask

Is there an httpx.load_cookies(path) helper?
Not in httpx. Use cookiejar, then cookies.set. Third-party wrappers exist; this snippet uses the stdlib only.
Do Secure cookies work on http://localhost?
Browsers special-case localhost; httpx does not have to. If secure is true, call HTTPS or expect the client to withhold the cookie.
Can I pass a Cookie header instead?
Yes — convert to Header String and set headers={"Cookie": ...}. You lose jar matching. Fine for a single host.
3 min read

Python Requests CookieJar from JSON

Convert browser JSON to Netscape for Requests via MozillaCookieJar, or to a Cookie header. Set domains before you call the host.

Python requests cookiesMozillaCookieJar Open the guide
3 min read

curl -b cookies.txt from JSON Export

Turn a Chrome JSON export into the Netscape file curl -b and -c expect: tabs, #HttpOnly_ prefixes, Unix-second expiry and a trailing newline.

curl cookies.txtcurl -b cookies Open the guide
3 min read

wget --load-cookies File from JSON

Convert a JSON cookie export to Netscape cookies.txt for wget --load-cookies. Keep session cookies with --keep-session-cookies or wget will drop expiry 0 on save.

wget --load-cookieswget cookies.txt Open the guide

Apply this on live cookies

The converter rewrites files. The extension reads and writes the jar in Chrome, including HttpOnly cookies.

Free and MIT-licensed · Chrome, Edge and other Chromium browsers · Nothing leaves your machine