Python Forum

Full Version: How to use Session Tokens
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I make my request from a server:
    obj = requests.Session()
    response = obj.request('get','https://192.168.0.22/api/', auth = HTTPBasicAuth(userName, password), verify = False)
    print(response.headers)
Here is the first part of the returned header; the server creates the session token:


'SessionToken': 'UVFlMTJJSENVTllpdThOR3hrZVpPY2dPQUR0c2MwZWtMYWFRdWZKam50S1AwRmVZNWZ0ZUliRENDbWFZNnJFUTJ3K2YzRmZxNVFXRk5USEJIcCtvUWc9PQ==', 'Set-Cookie': 'SessionToken="QQe12IHCUNYiu8NGxkeZOcgOADtsc0ekLaaQufJjntKP0FeY5fteIbDCCmaY6rEQ2w+f3Ffq5QWFNTHBHp+oQg=="

Now I want to make more requests with
'session_token': 'UVFlMTJJSENVTllpdThOR3hrZVpPY2dPQUR0c2MwZWtMYWFRdWZKam50S1AwRmVZNWZ0ZUliRENDbWFZNnJFUTJ3K2YzRmZxNVFXRk5USEJIcCtvUWc9PQ=='

def make_authenticated_request(url, session_token):
    headers = {'Authorization': 'Bearer ' + session_token}
    response = requests.get(url, headers=headers, verify = False)
    
my status code returns 401. What am I dong wrong?
How do I code in order use the header information originally provided by the server?

thank you.

first post
Why you do not copy response.headers (using response.headers.copy()) to your headers variable?