Cookies must be enabled in your browser [Python Requests]

北战南征 提交于 2019-12-19 10:22:41

问题


So I'm trying to log into my hotmail account via python and keep getting this response on the page when I make this request

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.

I would also like to mention that I am trying to httpPOST to this webpage because I would rather handle the cookies in the response and access other pages of my microsoft profile (rather than just accessing my email via the smtp server)

Thanks!

Edit :

import requests

s = requests.Session()
r = s.get('https://login.live.com',verify=False)
r = s.post('https://login.live.com', auth=('user', 'pass'),verify=False)
print r.status_code
print r.text

回答1:


Use requests.Session to persist a session (with cookies included):

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)


来源:https://stackoverflow.com/questions/35516483/cookies-must-be-enabled-in-your-browser-python-requests

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!