Navkarn
Navkarn

Reputation: 33

How to pass Jwt Token in python for request.get()

Not able to pass authentication key correctly.

I am trying to perform requests.get() using token, have tried multiple way to pass the argument but no luck so far.

import requests
import json

myToken = 'ABCD'  #(Dummy token, have copied actual token from session storage in chrome)
myUrl ='http://10.197.194.137/'

head = {'Authorization': 'token {}'.format(myToken) +myToken}
headers = {'content-type': 'application/json'}

response = requests.get(url = myUrl,headers=head)

pastebin_url = response.text 

print(pastebin_url);

Error : Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine.

Kindly explain best practice of using authentication using Token.

Upvotes: 3

Views: 11626

Answers (1)

user11044402
user11044402

Reputation:

This

head = {'Authorization': 'token {}'.format(myToken) +myToken}

is probably wrong.

  • You append myToken twice.
  • The value of the Authorization header should be Bearer ${myToken}.

Do this:

head = {'Authorization': 'Bearer {}'.format(myToken)}

Upvotes: 5

Related Questions