I am trying to get an API query into python. The command line
curl --header "Authorization:access_token myToken" https://website.com/id
gives some json output. myToken is a hexadecimal variable that remains constant throughout. I would like to make this call from python so that I can loop through different ids and analyze the output. Any ideas? Before authentication was needed I have done that with urllib2. I have also taken a look at the requests module but couldn't figure out how to do that.
Many thanks.
I had the same problem when trying to use a token with Github.
The only syntax that has worked for me with Python 3 is:
The requests package has a very nice API for HTTP requests, adding a custom header works like this (source: official docs):
If you don't want to use an external dependency, the same thing using urllib2 of the standard library looks like this (source: the missing manual):