Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to use Session Tokens
#1
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
Reply
#2
Why you do not copy response.headers (using response.headers.copy()) to your headers variable?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to get rid of numerical tokens in output (webscraping issue)? jps2020 0 1,966 Oct-26-2020, 05:37 PM
Last Post: jps2020

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020