Reputation: 33
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
Reputation:
This
head = {'Authorization': 'token {}'.format(myToken) +myToken}
is probably wrong.
myToken
twice.Authorization
header should be Bearer ${myToken}
.Do this:
head = {'Authorization': 'Bearer {}'.format(myToken)}
Upvotes: 5