- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Retrieving Cookies in Python
It is very easy to retrieve all the set cookies. Cookies are stored in CGI environment variable HTTP_COOKIE and they will have following form −
key1 = value1;key2 = value2;key3 = value3....
Here is an example of how to retrieve cookies.
#!/usr/bin/python # Import modules for CGI handling from os import environ import cgi, cgitb if environ.has_key('HTTP_COOKIE'): for cookie in map(strip, split(environ['HTTP_COOKIE'], ';')): (key, value ) = split(cookie, '='); if key == "UserID": user_id = value if key == "Password": password = value print "User ID = %s" % user_id print "Password = %s" % password
This produces the following result for the cookies set by above script −
User ID = XYZ Password = XYZ123
- Setting up Cookies in Python
- Using Cookies in CGI in Python
- How do cookies work in Python CGI Programming?
- How to setup cookies in Python CGI Programming?
- How to retrieve cookies in Python CGI Programming?
- Retrieving Elements from Collection in C#
- Assign Cookies in C++
- How to work with cookies in Selenium with python?
- What are Cookies?
- Facing Problem in retrieving HTML5 video duration
- Retrieving Elements from Collection in Java- EnumerationIterator
- Retrieving Elements from Collection in Java- ListIterator
- Retrieving Elements from Collection in Java- Iterator
- What are cookies in JSP?