0

how can i make this request in python using requests library.

curl -H "Authorization: 563492ad6f91700001000001e4d5ce6a4c3986a01" "http://api.pexels.com/v1/search?query=people"

I tried using this code , but it not working for some reason.

from requests.auth import HTTPBasicAuth
requests.get('http://api.pexels.com/v1/search?query=sea&per_page=15&page=1', auth=HTTPBasicAuth('Authorization' : '563492ad6f91700001000001e4d5ce6a4c3986a01'))
3
  • Is that header really correct? This looks like a breach of RFCs 7235 and 7236. Anyhow, what you are attempting to do there is clearly not "basic" auth. Commented Feb 7, 2017 at 13:18
  • @DaSourcerer i'm trying to use this api pexels.com/api what exactly i'm doing wrong. Commented Feb 7, 2017 at 13:27
  • 1
    Probably nothing. Those who designed that API are not conforming to the relevant RFCs: The Authorization header requires a token identifying the authentication scheme. Just tossing a token in there does not qualify. Commented Feb 7, 2017 at 13:31

1 Answer 1

3

I think auth for this requires just a header with proper data, so I would try it like this:

requests.get("http://api.pexels.com/v1/search?query=people", headers={
    "Authorization": "563492ad6f91700001000001e4d5ce6a4c3986a01"
})

It corresponds exactly to the curl request with -H flag

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.