nia4life
nia4life

Reputation: 363

CURL Python Issue When Hitting an API

The API I want to access is having me use CURL, something I'm unfamiliar with. I'm on windows using pycharm/spyder IDE (I can use both).

I've only used the library requests so not sure how to proceed. I tried the approach below using requests but got the error: "TypeError: 'str' object is not callable." I researched answers here but couldn't find a resolution.

What the API documentation says:

    $ curl -H "X-ABCD-Key: api_key" \
    https://api.abcd.com/searches.json

My approach:

    import requests
    url = "https://api.abcd.com/searches.json"
    auth = ("api_key")
    r = requests.get(url, auth=auth)
    print(r.content)

Upvotes: 0

Views: 37

Answers (1)

buran
buran

Reputation: 14273

try

import requests
headers = {'X-ABCD-Key': 'api_key'}
response = requests.get('https://api.abcd.com/searches.json', headers=headers)

Upvotes: 1

Related Questions