Reputation: 531
I'm trying to get the sessionId, so i can do other requests.
So i looked in the Firefox Network monitor (Ctrl+Shift+Q) and saw this:
So i wondered how i could do the request in python 3 and tried things like this:
import requests
payload = {'uid' : 'username',
'pwd' : 'password'}
r = requests.get(r'http://192.168.2.114(cgi-bin/wwwugw.cgi', data=payload)
print r.text
But I always get "Response [400]".
If the request is correct, I should get something like this:
Thanks
Alex
Upvotes: 2
Views: 26925
Reputation: 653
if you want to get the Session ID you can use Session()
from the requests
library:
URL = "Some URL here"
client = requests.Session()
client.get(URL)
client.cookies['sessionid']
Upvotes: 2
Reputation: 1851
Just use a session, which will handle redirects and cookies for you:
import requests
payload = {'uid' : 'username',
'pwd' : 'password'}
with requests.Session() as session:
r = session.post(r'http://192.168.2.114(cgi-bin/wwwugw.cgi', data=payload)
print(r.json)
This way you don't explicitly need to get the sessionId
, but if you still want to, you can access the returned JSON
as a dictionary.
Upvotes: 3
Reputation: 16753
Although it's not very clear from your question, but I've noticed few issues with what you are trying to accomplish.
If you are using session authentication, then you are suppose the send session_id as a Cookie
header, which you aren't doing.
400 response code means bad request, not authentication required. Why are you sending data in get
request to begin with? There's a difference between data and query params.
Upvotes: 1