Nov-21-2020, 11:00 AM
Hello, I wrote the following code and ran it:
#!/usr/bin/python3
# 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)The result I was supposed to get is:User ID = XYZ Password = XYZ123I got an error:
Python 3.6.9 (default, Oct 8 2020, 12:12:24)
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license()" for more information.
>>>
==== RESTART: /home/user/Desktop/Programming/Python/Retrieving Cookies.py ====
Traceback (most recent call last):
File "/home/user/Desktop/Programming/Python/Retrieving Cookies.py", line 5, in <module>
if environ.has_key('HTTP_COOKIE'):
AttributeError: '_Environ' object has no attribute 'has_key'
>>>
