0

I'm following this tutorial ("Getting data from your Zendesk product") and I got a Response [200], which supposedly means that my request was successful. However when I did data = response.json(), I received the JSONDecoder error JSONDecodeError: Expecting value: line 1 column 1 (char 0). I've tried debugging with the different solutions from other Stackoverflow solutions, but it hasn't worked. Please illuminate me!

1 Answers1

0

Without being able to see the code in thq question, the first (or most likely) error is that the response type might not be json. So whilst you are getting a success (200) the return value is likely to be text.

In the past i have used something like this:

import requests

url = 'https://www.whois.com/whois/'

r = requests.get(url)


if r.status_code==200:
    # page works, check if text or json response
    if r.headers['Content-Type'] == 'text/html; charset=UTF-8':
        print(r.text)
    
    
else:
    print('no website')

The alternative response type for json is:

'application/json; charset=utf-8'

So you could check for this directly.

D.L
  • 4,339
  • 5
  • 22
  • 45
  • Hi there, thank you for your response! I included your code and it printed out a bunch of HTML gibberish :| i think ill contact zendesk developer community then. Thanks anyway! – Elizabeth Hudson May 02 '22 at 08:31
  • 1
    You are welcome, in the link that you posted one of the comments is that the `json` might not be properly formed. This might be the case for you. Also, you might wish to post the "gibberish" as it could be meaningful to resolving the problem.... – D.L May 02 '22 at 14:42