必须在浏览器中启用Cookie [Python请求] [英] Cookies must be enabled in your browser [Python Requests]

查看:269
本文介绍了必须在浏览器中启用Cookie [Python请求]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我试图通过python登录到我的hotmail帐户,并在发出此请求时在页面上不断收到此响应

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.

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

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)

谢谢!

编辑:

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


推荐答案

使用 requests.Session 来保持会话(包括cookie):

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)

这篇关于必须在浏览器中启用Cookie [Python请求]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆