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

编程入门 行业动态 更新时间:2024-10-07 13:17:38
本文介绍了必须在浏览器中启用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('login.live', 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('login.live',verify=False) r = s.post('login.live', 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('login.live') cookies = dict(res.cookies) res = s.post('login.live', auth=('Email', 'Password'), verify=False, cookies=cookies)

更多推荐

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

本文发布于:2023-11-12 14:29:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1581747.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:器中   Cookie   Python

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!