尝试检查cookie -Python时,未定义NameError名称“request”

时间:2015-12-08 20:48:04

标签: python python-2.7 cookies request

当我尝试检查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:未定义名称“请求”

2 个答案:

答案 0 :(得分:0)

也许您需要存储响应并在那里查找Cookie:

resp = requests.post(...)
if resp.cookies['blahblah']:

答案 1 :(得分:0)

我认为您只需将其更改为requests而不是request