0

I am working on helpshift api and trying to find an accurate request call that will return an the Issue metadata. I have tried many examples but it always returns 401 status.

However I was able to get the curl command to work

Things provided to me is : apikey, url, and return is json response

the working CURL command is :

curl -X GET --header 'Accept: application/json' --header 'Authorization: Basic <base64_encoded_version_of_api_key_for_basic_auth>' '<helpshift_url>'

The things I have tried are as follow:

>>> api_key = "ABCDEFGH"
>>> issue = '<helpshift_url>'
>>> 
>>> r = requests.get( issue, auth = ( api,"" ))
>>> r.status_code
401
>>> 
>>> import base64
>>> api_new = base64.b64encode(api_key.encode("UTF-8"))
>>> 
>>> r = requests.get( issue, auth = ( api_new,"" ))
>>> r.status_code
401

what I am trying to get is json response printed

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Ashish Kumar
  • 126
  • 11

2 Answers2

0

requests auth param is responsible for http basic auth. From what I see in your code, instead of performing auth you want to modify the headers.

This is done by passing a headers dict headers = {'Authorization': api_new} to requests as r = requests.get( issue, headers=headers).

Full code being

import base64
import requests

api_key = "ABCDEFGH"
issue = '<helpshift_url>'

api_new = base64.b64encode(api_key.encode("UTF-8"))
headers = {'Authorization': api_new}

r = requests.get( issue, headers=headers)


Simas Joneliunas
  • 2,890
  • 20
  • 28
  • 35
0

You need to use a header:

>>> import base64
>>> api_new = base64.b64encode(api_key.encode("UTF-8"))
>>> 
>>> r = requests.get( issue, header="Authorization: Basic {}'.format(api_new))
Paul Joireman
  • 2,689
  • 5
  • 25
  • 33