'Python requests by session id

I have 2 different urls, one for getting an session id, other one is for requesting (post/get) with the session id obtained via first url. When I use postman for that, everthing works fine but in case of python requests, obtained sessionID does not recognized by requests to second url.

How can I overcome this problem? What is the differences between the postman requests and python requests?

If session ID obtained via postman and used in python requests, it works fine also. However the session ID obtained via Python does not working neither in python and postman.



Solution 1:[1]

were you using python requests? If yes, Use requests' session.

import requests
session = requests.session()
session.post("<your htttp url>", <post params>)
session.get("<your http second url>")

Requests session takes care for sending back sessionid if it is in cookies. If it is a separate header. You should check for response.status_code. usually python requests packager will not create error.

print(response.status_code)
# mostly you are getting session_id but response status code is not 20X for first request

Use dothttp.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1