Dilli Dilli - 4 months ago 25
Python Question

How would I pass in authtoken in my browser get Requests

How would I make following requests

$ curl -u eyJhbGciOiJIUzI1NiIsImV4cCI6MTM4NTY2OTY1NSwiaWF0IjoxMzg1NjY5MDU1fQ.eyJpZCI6MX0.XbOEFJkhjHJ5uRINh2JA1BPzXjSohKYDRT472wGOvjc:unused -i -X GET
HTTP/1.0 200 OK
Content-Type: application/json

Work on my python-get requests without having to use my login information but just my auth token like how I made it working on curl?

I tried the following code it throws me
unauthorized access

response = requests.get('', headers={'Authorization':'eyJhbGciOiJIUzI1NiIsImV4cCI6MTQ3Nzc3MTE2MiwiaWF0IjoxNDc3NzcwNTYyfQ.eyJpZCI6MX0.3IbZmxhDXxymOzXBKnv-rbMDBV_nFYaf-IWIW5YBnWE:unused'})
print response.text


In the curl manpage:

-u, --user <user:password>
    Specify the user name and password to use for server authentication.

In the requests documentation requests documentation:

from requests.auth import HTTPBasicAuth
requests.get('https://api.github.com/user', auth=HTTPBasicAuth('user', 'pass'))

So the following might work (untested):

from requests.auth import HTTPBasicAuth
response = requests.get('', auth=HTTPBasicAuth('eyJhbGciOiJIUzI1NiIsImV4cCI6MTQ3Nzc3MTE2MiwiaWF0IjoxNDc3NzcwNTYyfQ.eyJpZCI6MX0.3IbZmxhDXxymOzXBKnv-rbMDBV_nFYaf-IWIW5YBnWE','unused')
print response.text