Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
3 views
in Python by (16.4k points)

I'm utilizing the requests module. I have sorted out some way to submit information to a login structure on a site and recover the meeting key, however, I can't see an undeniable method to utilize this meeting key in resulting demands. Would someone be able to fill in the ellipsis in the code underneath or propose another methodology?

>>> import requests

>>> login_data =  {'formPosted':'1', 'login_email':'[email protected]', 'password':'pw'}

>>> r = requests.post('https://localhost/login.py', login_data)

>>> 

>>> r.text

u'You are being redirected <a href="profilePage?_ck=1349394964">here</a>'

>>> r.cookies

{'session_id_myapp': '127-0-0-1-825ff22a-6ed1-453b-aebc-5d3cf2987065'}

>>> 

>>> r2 = requests.get('https://localhost/profile_data.json', ...)

1 Answer

0 votes
by (26.4k points)

You can undoubtedly make a persistent meeting utilizing: 

s = requests.Session()

From that point onward, proceed with your requests as you would:

s.post('https://localhost/login.py', login_data)

#logged in! cookies saved for future requests.

r2 = s.get('https://localhost/profile_data.json', ...)

#cookies sent automatically!

#do whatever, s will keep your cookies intact :)

Want to learn python to get expertise in the concepts of python? Join python certification course and get certified

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...