     [Answers](https://scrapfly.io/blog)   /  [http](https://scrapfly.io/blog/tag/http)   /  [How to save and load cookies in Python requests?](https://scrapfly.io/blog/answers/save-and-load-cookies-in-requests-python)   # How to save and load cookies in Python requests?

 by [Bernardas Alisauskas](https://scrapfly.io/blog/author/bernardas) Apr 18, 2026 2 min read [\#http](https://scrapfly.io/blog/tag/http) [\#python](https://scrapfly.io/blog/tag/python) [\#requests](https://scrapfly.io/blog/tag/requests) 

 [  ](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fscrapfly.io%2Fblog%2Fanswers%2Fsave-and-load-cookies-in-requests-python "Share on LinkedIn")    

 

 

HTTP cookies in web scraping play a vital role across several factors, including blocking and localization. Hence, pausing and resuming request sessions is often useful. For this, we'll explain how to save and load Python requests cookies.



## Save Cookies

Let's start by saving cookies in Python requests. For this, we'll use the `requests.cookiejar` utility package:

python```python
from pathlib import Path
from requests.utils import dict_from_cookiejar
import json
import requests

# create a session to presists cookies
session = requests.session()

# send cookies through a response object
session.get("https://httpbin.dev/cookies/set?key1=value1&key2=value2")

# turn cookiejar into dict
cookies = dict_from_cookiejar(session.cookies)  

# save them to file as JSON
Path("cookies.json").write_text(json.dumps(cookies))
```



Above, we create a new session object and request a URL to accept few cookie values. Then, we save the retrieved Python request cookies to an object using the `dict_from_cookiejar` method. Finally, the cookie data is saved to a JSON file:

json```json
{"key1": "value1", "key2": "value2"}
```





Scrapfly

#### Scale your web scraping effortlessly

Scrapfly handles proxies, browsers, and anti-bot bypass — so you can focus on data.

[Try Free →](https://scrapfly.io/register)## Load Cookies

Now that we saved the cookie object using Python cookiejar, let's load it:

python```python
from pathlib import Path
from requests.utils import cookiejar_from_dict
import json
import requests

# create a session
session = requests.session()

# load the JSON file
cookies = json.loads(Path("cookies.json").read_text())

# turn the object into a a cookie jar
cookies = cookiejar_from_dict(cookies)

# load cookiejar to current session
session.cookies.update(cookies)

# validate the cookies
print(session.get("https://httpbin.dev/cookies").text)
{"key1": "value1", "key2": "value2"}
```



Here, we started by loading the JSON file and importing the cookie values using the `cookiejar_from_dict`. Next, we let the requests set cookie values by loading them into the session, which will automatically set cookie header values.



For further details on utilizing cookies for requests in Python, refer to our dedicated guide.

[How to Handle Cookies in Web ScrapingIntroduction to cookies in web scraping. What are they and how to take advantage of cookie process to authenticate or set website preferences.](https://scrapfly.io/blog/posts/how-to-handle-cookies-in-web-scraping)



 

    Table of Contents- [Save Cookies](#save-cookies)
- [Load Cookies](#load-cookies)
 
    Join the Newsletter  Get monthly web scraping insights 

 

  



Scale Your Web Scraping

Anti-bot bypass, browser rendering, and rotating proxies, all in one API. Start with 1,000 free credits.

  No credit card required  1,000 free API credits  Anti-bot bypass included 

 [Start Free](https://scrapfly.io/register) [View Docs](https://scrapfly.io/docs/onboarding) 

 Not ready? Get our newsletter instead. 

 

## Explore this Article with AI

 [ ChatGPT ](https://chat.openai.com/?q=Summarize%20this%20page%3A%20https%3A%2F%2Fscrapfly.io%2Fblog%2Fanswers%2Fsave-and-load-cookies-in-requests-python) [ Gemini ](https://www.google.com/search?udm=50&aep=11&q=Summarize%20this%20page%3A%20https%3A%2F%2Fscrapfly.io%2Fblog%2Fanswers%2Fsave-and-load-cookies-in-requests-python) [ Grok ](https://x.com/i/grok?text=Summarize%20this%20page%3A%20https%3A%2F%2Fscrapfly.io%2Fblog%2Fanswers%2Fsave-and-load-cookies-in-requests-python) [ Perplexity ](https://www.perplexity.ai/search/new?q=Summarize%20this%20page%3A%20https%3A%2F%2Fscrapfly.io%2Fblog%2Fanswers%2Fsave-and-load-cookies-in-requests-python) [ Claude ](https://claude.ai/new?q=Summarize%20this%20page%3A%20https%3A%2F%2Fscrapfly.io%2Fblog%2Fanswers%2Fsave-and-load-cookies-in-requests-python) 



 ## Related Articles

 [  

 http 

### How to Handle Cookies in Web Scraping

Introduction to cookies in web scraping. What are they and how to take advantage of cookie process to authenticate or se...

 

 ](https://scrapfly.io/blog/posts/how-to-handle-cookies-in-web-scraping) [  

 http python 

### Guide to Python requests POST method

Discover how to use Python's requests library for POST requests, including JSON, form data, and file uploads, along with...

 

 ](https://scrapfly.io/blog/posts/how-to-python-requests-post) [  

 http python 

### Guide to Python Requests Headers

Our guide to request headers for Python requests library. How to configure and what do they mean.

 

 ](https://scrapfly.io/blog/posts/python-requests-headers-guide) 

  ## Related Questions

- [ Q How to save and load cookies in Playwright? ](https://scrapfly.io/blog/answers/how-to-save-and-load-cookies-in-playwright)
- [ Q How to save and load cookies in Selenium? ](https://scrapfly.io/blog/answers/how-to-save-and-load-cookies-in-selenium)
- [ Q How to save and load cookies in Puppeteer? ](https://scrapfly.io/blog/answers/how-to-save-and-load-cookies-in-puppeteer)
- [ Q What is HTTP cookies role in web scraping? ](https://scrapfly.io/blog/answers/http-cookies-in-web-scraping)
 
  



   



 Scale your web scraping effortlessly, **1,000 free credits** [Start Free](https://scrapfly.io/register)