
- Requests Tutorial
- Requests - Home
- Requests - Overview
- Requests - Environment Setup
- Requests - How Http Requests Work?
- Requests - Working with Requests
- Handling Response for HTTP Requests
- Requests - HTTP Requests Headers
- Requests - Handling GET Requests
- Handling POST, PUT, PATCH & DELETE Requests
- Requests - File Upload
- Requests - Working with Cookies
- Requests - Working with Errors
- Requests - Handling Timeouts
- Requests - Handling Redirection
- Requests - Handling History
- Requests - Handling Sessions
- Requests - SSL Certification
- Requests - Authentication
- Requests - Event Hooks
- Requests - Proxy
- Requests - Web Scraping using Requests
- Requests Useful Resources
- Requests - Quick Guide
- Requests - Useful Resources
- Requests - Discussion
Requests - Working with Cookies
This chapter will discuss how to deal with cookies. You can get the cookies as well as send your cookies while calling the URL using the requests library.
The url, https://jsonplaceholder.typicode.com/users when hits in the browser we can get the details of the cookies as shown below −

You can read the cookies as shown below −
Example
import requests getdata = requests.get('https://jsonplaceholder.typicode.com/users') print(getdata.cookies["__cfduid"])
Output
E:\prequests>python makeRequest.py d1733467caa1e3431fb7f768fa79ed3741575094848
You can also send cookies when we make a request.
Example
import requests cookies = dict(test='test123') getdata = requests.get('https://httpbin.org/cookies',cookies=cookies) print(getdata.text)
Output
E:\prequests>python makeRequest.py { "cookies": { "test": "test123" } }
Advertisements