question

kvakati avatar image
kvakati asked ·

getting 401 when calling from Requests library in python but works from postman

import requests

import json

cloverUrl='https://apisandbox.dev.clover.com/v3/merchants/XXXX'

apiHeader={'Authorization': 'Bearer {xxcxcxcxc}',"accept": "application/json"}

orders=requests.get(cloverUrl,apiHeader)

print(orders)


API call fails with 401 but same is successful when calling from post man.

Auth
10 |2000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

kvakati avatar image
kvakati answered ·

url = "https://apisandbox.dev.clover.com/v3/merchants/XXXX"

payload={}

headers = {

'accept': 'application/json',

'Authorization': 'Bearer xcxcxcxcx'

}

response = requests.request("GET", url, headers=headers, data=payload)

print(response.text)

This worked.

Thanks

10 |2000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

kvakati avatar image
kvakati answered ·

Hi I tried removing {} but still the same.

6 comments
10 |2000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Remove the accept header, you are trying to make a get request (I just tried this and it works). If you look at the cUrl that is generated via Postman you will see it doesn't pass an accept header for gets.

0 Likes 0 ·
kvakati avatar image kvakati David Marginian ♦♦ ·

1607719906899.png

it did not work

0 Likes 0 ·
1607719906899.png (36.2 KiB)

From your screenshot it also looks like you are missing the "/orders" path after the merchant id.

0 Likes 0 ·
Show more comments
David Marginian avatar image
David Marginian answered ·

It looks like you are passing { and } in your bearer value. Try 'Bearer xxcxcxcxc' instead of 'Bearer {xxcxcxcxc}'.

10 |2000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Welcome to the
Clover Developer Community