-2

I am querying an api with postman which requires the following header/auth to set enter image description here

How do I set these params programmatically in requests library or some other library

frazman
  • 32,081
  • 75
  • 184
  • 269
  • 1
    from here https://stackoverflow.com/a/19072991/15020017 requests.get('url', headers={'Authorization': 'token'}) – Dennis Jan 30 '21 at 16:48
  • Check this [link](https://requests.readthedocs.io/en/master/user/quickstart/#custom-headers) – Chiheb Nexus Jan 30 '21 at 16:49
  • Does this answer your question? [Python requests library how to pass Authorization header with single token](https://stackoverflow.com/questions/19069701/python-requests-library-how-to-pass-authorization-header-with-single-token) – CryptoFool Jan 30 '21 at 17:29
  • @Dennis @Steve: No this is not working.. I have tried `headers = {'Authorization' :'X-API-KEY:MY_API_KEY'}` but its not working (403 error) – frazman Jan 30 '21 at 20:21
  • Maybe the key is not right?@frazman – Dennis Jan 30 '21 at 20:44
  • 1
    @Dennis: I was able to figure this out (answered my own question below :) ) – frazman Jan 30 '21 at 22:51
  • Nice it worked @frazman – Dennis Jan 30 '21 at 22:59

1 Answers1

1

Answering my own question.. as none of the suggestions mentioned in the comments worked for me.

headers = {
  'X-API-KEY': 'API_KEY'
}

response = requests.request("GET", url, headers=headers)
print(response.text)
frazman
  • 32,081
  • 75
  • 184
  • 269