3 min read

Load a Requests CookieJar from JSON or cookies.txt

Python Requests loads Netscape files with http.cookiejar.MozillaCookieJar; convert a Chrome JSON export to cookies.txt here, then jar.load() before requests.get.

A JSON map of name→value is not enough for a jar: it has no domain. If you only have a map, convert to JSON Array, set domain, then export Netscape.

Python requests cookiesMozillaCookieJarrequests cookies.txtrequests CookieJar
  1. 1
    Get a full-fidelity export

    CookieMan JSON Array, not a JSON map. Maps default every cookie to localhostJSON Map vs JSON Array.

  2. 2
    Convert to Netscape

    Paste the array. Download cookies.txt. HttpOnly becomes #HttpOnly_, which MozillaCookieJar understands.

  3. 3
    Load the jar in Requests

    Use the snippet below. Point requests.get at a URL whose host matches column 1 of the file.

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

Working Requests snippet

            from http.cookiejar import MozillaCookieJar
import requests

jar = MozillaCookieJar("cookies.txt")
jar.load(ignore_discard=True, ignore_expires=True)
session = requests.Session()
session.cookies = jar
response = session.get("https://example.com/dashboard")
print(response.status_code)
          
ignore_expires=True loads expired rows for debugging. Do not ship that flag in production jobs. Cookie files are credentials — keep them out of source control.

Header-only alternative

If you only need one call and do not care about Domain matching, convert to Header String and pass headers={"Cookie": "..."}. That bypasses the jar and will not store Set-Cookie from the response unless you also use a Session.

Input you haveConvert toRequests API
JSON Array with domainsNetscapeMozillaCookieJar.load
JSON ArrayHeader Stringheaders={"Cookie": ...}
JSON MapJSON Array, then edit domainsDo not load a map as a jar

Questions people ask

Does Requests parse CookieMan JSON directly?
No. Use Netscape + MozillaCookieJar, or iterate the JSON and session.cookies.set(name, value, domain=..., path=...).
Why does MozillaCookieJar skip my lines?
Spaces instead of tabs, or a missing newline. Re-export from this converter. Session rows use expiry 0; that is valid.
http.cookiejar vs requests.cookies?
requests.Session.cookies is a RequestsCookieJar that wraps cookiejar. Assigning a loaded MozillaCookieJar works. httpx is a different client — httpx cookies from Netscape.
3 min read

httpx Cookies from Netscape File

Convert JSON or a Cookie header to Netscape cookies.txt and load it in httpx.Client. httpx has no cookies.txt reader — use http.cookiejar, then copy into the client.

httpx cookieshttpx cookies.txt 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

JSON Map vs JSON Array Cookie Export

A JSON map is name→value only. CookieMan fills domain=localhost, path=/, session=true and warns. Use JSON Array when you need to import into Chrome.

JSON map cookiesJSON array vs map 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