
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Setting up Cookies in Python
It is very easy to send cookies to browser. These cookies are sent along with HTTP Header before to Content-type field. Assuming you want to set UserID and Password as cookies. Setting the cookies is done as follows −
Example
#!/usr/bin/python print "Set-Cookie:UserID = XYZ;\r\n" print "Set-Cookie:Password = XYZ123;\r\n" print "Set-Cookie:Expires = Tuesday, 31-Dec-2007 23:12:40 GMT";\r\n" print "Set-Cookie:Domain = www.tutorialspoint.com;\r\n" print "Set-Cookie:Path = /perl;\n" print "Content-type:text/html\r\n\r\n" ...........Rest of the HTML Content....
From this example, you must have understood how to set cookies. We use Set-Cookie HTTP header to set cookies.
It is optional to set cookies attributes like Expires, Domain, and Path. It is notable that cookies are set before sending magic line "Content-type:text/html\r\n\r\n.
- Related Articles
- Setting up Background Color in CSS
- Setting up C++ Development Environment
- Setting up Background Color using CSS
- Role of Crafts in Setting Up Trending Fashion
- Retrieving Cookies in Python
- Setting up a Poster for a Video in Video.js Player
- Using Cookies in CGI in Python
- Setting up a JDBC connection to remote SAP HANA system
- Setting up Virtual Machines for your Microsoft Azure Cloud platform
- How do cookies work in Python CGI Programming?
- How to setup cookies in Python CGI Programming?
- How to retrieve cookies in Python CGI Programming?
- How to use ansible for setting up production elasticsearch servers with cluster
- Setting Background color for Tkinter in Python
- How to work with cookies in Selenium with python?

Advertisements