Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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' https://api.mailgun.net/v3/mydomain.net/events

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 curl directly inside Python?

like image 484
Richard Avatar asked Oct 28 '16 16:10

Richard


1 Answers

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

my_req = requests.get('https://api.mailgun.net/v3/mydomain.net/events', auth=('user', 'pass')
like image 129
Dalvenjia Avatar answered Oct 17 '22 09:10

Dalvenjia