Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cookies must be enabled in your browser [Python Requests]

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
like image 625
k9b Avatar asked Feb 19 '16 22:02

k9b


People also ask

How do I send a cookie request in Python?

To send a request with a Cookie, you need to add the "Cookie: name=value" header to your request. To send multiple cookies in a single Cookie header, separate them with semicolons or add multiple "Cookie: name=value" request headers.

What are cookies in Python?

cookies module defines classes for abstracting the concept of cookies, an HTTP state management mechanism. It supports both simple string-only cookies, and provides an abstraction for having any serializable data-type as cookie value.

How do I enable cookies for HTML?

Open Google Chrome. From the web browser menu in the top-right corner, select Settings > Site settings > Cookies. From the Cookies menu, toggle the button on the right to Allow sites to save and read cookie data (recommended). Refresh the Chrome browser to enable cookies.


1 Answers

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)
like image 77
leongold Avatar answered Sep 30 '22 13:09

leongold