[英]NameError name 'request' is not defined when trying to check for cookie -Python
我在尝试检查Cookie是否存在时遇到以下问题。
import requests
username = raw_input('Please enter your username: ')
password = raw_input('Please enter your password: ')
DATA = {
"url": "http://example.com/index.php",
"action": "do_login",
"submit": "Login",
"quick_login": "1",
"quick_username": (username),
"quick_password": (password),
}
requests.post("http://example.com/member.php", data=DATA)
if 'mybbuser' in request.COOKIES.keys():
print("Correct")
else:
print("Wrong")
我得到的错误:
NameError:未定义名称“请求”
也许您需要存储响应并在此处查找cookie:
resp = requests.post(...)
if resp.cookies['blahblah']:
我认为您只需要将其更改为requests
而不是request
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.