必须在浏览器中启用Cookie [Python请求]

时间:2016-02-19 22:45:42

标签: python cookies python-requests

所以我试图通过python登录我的hotmail帐户,并在我提出此请求时继续在页面上获得此响应

UITextField

我还想提一下,我正在尝试httpPOST到这个网页,因为我宁愿在响应中处理cookie并访问我的微软配置文件的其他页面(而不是仅通过smtp服务器访问我的电子邮件)

谢谢!

编辑:

r = requests.post('https://login.live.com', auth=('Email', 'Pass'),verify=False)

Cookies must be allowed

Your browser is currently set to block cookies. Your browser must allow cookies before you can use a Microsoft account.

Cookies are small text files stored on your computer that tell Microsoft sites and services when you're signed in. To learn how to allow cookies, see online help in your web browser.

1 个答案:

答案 0 :(得分:5)

使用requests.Session来保持会话(包含Cookie):

import requests

s = requests.Session()
res = s.get('https://login.live.com')
cookies = dict(res.cookies)
res = s.post('https://login.live.com', 
    auth=('Email', 'Password'),
    verify=False, 
    cookies=cookies)