Sending Request with Cookies [Python Code]

To send an HTTP request with a Cookie using Python, you need to add the "Cookie: name=value" header to your request. To send multiple cookies in a single Cookie header, separate them with semicolons or add multiple "Cookie: name=value" request headers. In this Python Cookies Request Example, we send cookies to the ReqBin echo URL. Click Send to execute Python Cookies Request Example online and see the results. The Python code was automatically generated for the Request Cookies example.
Sending Request with Cookies [Python Code] Send
GET /echo/get/json HTTP/1.1
Cookie: name=value; name2=value2

Updated: Viewed: 49555 times
Python code for Request Cookies example

Python code for Request Cookies Example

This Python code snippet was generated automatically for the Request Cookies example.
<< Back to the Request Cookies example

What is HTTP?

HTTP (Hypertext Transfer Protocol) is an application layer data transfer protocol. HTTP is used to transfer data between HTTP clients (browsers and mobile apps) and servers. HTTP is built on a request-response architecture between a client and a server. The client send a request to the server, then the server processes that request and send a response back to the client.

HTTP Cookies

HTTP Сookies is data sent from a website and stored by a web browser on a user's computer. Cookies are placed on the device (computer, mobile phone) used to access the website. These cookies are marked with an identifier that is unique to you and your computer. Cookies manage user sessions, track users and personalize (store site settings and user preferences). Browsers usually send cookies back to the server with each subsequent request, which allows the server to determine if the request came from the same browser or not.

HTTP Cookies Syntax

The following is the general syntax of the Cookies header:

Cookies Header Syntax
Cookie: cookie-name=value

What are Cookies used for?

Websites use HTTP cookies to improve the user experience when visiting the website. Cookies allow websites to remember you and do not require you to log in every time you visit a website. Cookies can keep the items in your cart and restore them when you visit the online store the next day. Cookies are stored locally on your device. If you delete cookies in your browser or visit the website in incognito mode, the website will not remember you, and you will become a new user who came to the website like the first time.

Cookies are used to:

  • Session Management: Websites use cookies to recognize users and remember their login information and settings.
  • Tracking: In shopping sites, cookies help track products that have previously been viewed by a user and show similar items.
  • Personalization: The primary way we use cookies is to display personalized ads. Advertisements can track your activities on various websites and create profiles tailored to your interests, which are then displayed in targeted ads.

How can I see saved cookies in my browser?

To view stored cookies in your browser:

  1. Press F12 to open the developer tool;
  2. Click on the Application tab;
  3. Under the "Storage" section open Cookies node and click on your website address;
  4. Here you will see all the cookies stored in your browser for this site.

How to send a Cookie request?

The following is an example of sending cookies to the server:

Send Cookies Example
GET /echo/get/json HTTP/1.1
Cookie: name=value; name2=value2

See also

Generate code snippets for Python and other programming languages

Convert your Request Cookies request to the PHP, JavaScript/AJAX, Node.js, Curl/Bash, Python, Java, C#/.NET code snippets using the Python code generator.