Issue
I am attempting to do session login that requires csrf token.
import requests
from requests import Session
login = ''
profile = ''
r = requests.get(login)
payload = {
'login': '',
'pass': '',
'logclick': '',
'uber_csrf_key': '',
'uber_csrf_token': '',
}
Session.post(url = login, cookies = r.cookies, data = payload)
test = Session.get(profile)
print(test)
This returns this error message:
TypeError: Session.post() missing 1 required positional argument: 'self'
and I am having a difficult time finding manual for this library. Is there a better way to do this?
Solution
You have imported Session
, but missed to instantiate it.
This should work:
import requests
from requests import Session
login = ''
profile = ''
sess = Session()
r = requests.get(login)
payload = {
'login': '',
'pass': '',
'logclick': '',
'uber_csrf_key': '',
'uber_csrf_token': '',
}
sess.post(url = login, cookies = r.cookies, data = payload)
test = sess.get(profile)
print(test)
sess.close()
You may put even the get request into the session, it would help to keep everything in one session.
You may official documentation here: https://docs.python-requests.org/en/latest/
Answered By - Anand Gautam
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.