Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Requests - Auth Token

I am using Python Requests 2.7.0, and I am trying to pass a authtoken for a Session. I am able to successfully connect using session.auth(user,pass), but I am unfamiliar with how to pass a authtoken into a session.

I tried using headers for the session, but this did not work. Here is the general flow of what I have:

session = requests.Session()
session.headers.update({'Authorization': TOKEN})
...
like image 255
djklein Avatar asked May 19 '15 16:05

djklein


1 Answers

You are correctly setting a header to be used for all requests sent with the session.

You are probably not setting the header value correctly, however. The Authorization header probably has to follow a specific pattern, as outlined in the documentation for the service you are contacting. It is typical that the value must start with a authentication scheme (like the Basic and Digest authentication schemes, so the value would be <scheme> <token>.

like image 71
Martijn Pieters Avatar answered Oct 21 '22 07:10

Martijn Pieters