0

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)

1 Answer 1

1

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)
Sign up to request clarification or add additional context in comments.

1 Comment

You Rock! Thank you so much for the answer and the explanation!! :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.