I tried searching for couple of hours, but nothing seem to be working. I am trying to login to a webpage to download some data. Each login requires a new cookie (PHPSESSID) since it expires when browsing connection ends. I tried the following:
import requests
payload = {'user':'myusername', 'password':'mypassword'}
url = 'blahblah.blah'
with requests.Session() as s:
r = s.get(url)
cookie = {'PHPSESSID': r.cookies['PHPSESSID']}
r = s.post(url, data=payload, cookies=cookie)
This, however, redirects to the login page, which I think means the login failed. I then tried to login through Chrome, and obtain the cookie manually. When I do this, I can use that cookie to login using requests.
with requests.Session() as s:
cookie = {'PHPSESSID': 'some value obtained by logging in through Chrome and copying the cookie value'}
r = s.post(url, cookies=cookie, data=payload)
The above works perfectly fine.
Im not sure what Im doing incorrectly in the original code. Any assistance is appreciated!