简体   繁体   中英

Connecting to oauth2 API - it works with curl, doesn't with requests.get (Python)

I've been trying to connect to an oauth2 API. I've managed to write a code that delivers a token, so the token is not a problem.

I've checked that with curl. The following works:

curl -X GET \
https://api.website.pl/sale/delivery-methods \
-H 'Authorization: Bearer eyJhbGciOiJSUzBmF1BWKBjk3GiA' \
-H 'accept: application/vnd.website.public.v1+json'

<- This returns the data I need.

However, I simply can't make it work in python.

headers = {}
headers['Authorization'] = 'Bearer eyJhbGciOiJSUzBmF1BWKBjk3GiA'
headers['Accept'] = 'application/vnd.website.public.v1+json'

get_url = 'https://api.website.pl/sale/delivery-methods'
requests.get(get_url, headers)

The response is <Response [406]>, incorrect data, which I'm interpreting as a signal I didn't pass all the relevant authorization headers.

Any ideas how to fix that?

try this:

headers = {}
headers['Authorization'] = 'Bearer eyJhbGciOiJSUzBmF1BWKBjk3GiA'
headers['Accept'] = 'application/vnd.website.public.v1+json'

get_url = 'https://api.website.pl/sale/delivery-methods'
response = requests.get(get_url, headers=headers)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM