Richard Richard - 2 months ago 17
Python Question

HTTP request equivalent of `curl --user` parameter?

I am retrieving events data from the Mailgun API. I am able to run this on the command line and get data back:

curl -s --user 'api:key-xxxx'

Now I want to script this with Python and requests. I know that it is possible to make a request using Basic-Auth to get the data via a URL. However, Mailgun says that API keys should be treated like a password, so I'd prefer not to expose API keys directly in the URLs if possible.

Is there any way I can do the equivalent of
curl --user
in requests, to supply the parameter but without exposing it in the URL?

Alternatively, would it be better to try to use
directly inside Python?


just add the auth=('user', 'passwd') argument to the get method, it has to be a tuple with 2 strings.

my_req = requests.get('', auth=('user', 'pass')