Reputation: 357
I am trying to convert the following curl
command to Python
request command:
curl 'https://api.test.com/v1/data/?type=name&status=active' -H 'Authorization: apikey username:api_key_value'
I have tried a lot of possible solutions like the one below but nothing is working and I am getting a'401' code:
url = "https://api.test.com/v1/data/?type=name&status=active"
headers = {"content-type": "application/json", "Accept-Charset": "UTF-8"}
params = (
(username, api_key_value),
)
data = requests.get(url, headers=headers, params=params).json
print(data)
Upvotes: 0
Views: 39
Reputation: 54698
Params specifies the URL parameters. The Authorization thing is just another header. And response.json
is a function.
url = "https://api.test.com/v1/data/"
headers = {
"content-type": "application/json",
"Accept-Charset": "UTF-8",
"Authorization": "apikey {0}:{1}".format(username, api_key_value)
}
params = { 'type': 'name', 'status': 'active' }
data = requests.get(url, headers=headers, params=params).json()
print(data)
Upvotes: 1