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!
Asked
Active
Viewed 105 times
0
-
2Please edit your question to show a [mcve] so it's possible to assist you. – import random May 02 '22 at 05:11
-
what'll be helpful? because i can't reveal my zendesk account details to access the API – Elizabeth Hudson May 02 '22 at 06:08
-
1The question suggests that response is probably `text` and not `json`. So try `response.text` initially. – D.L May 02 '22 at 06:44
-
You're trying to access `response.json()` before checking `response.status_code`. There is a good chance that your request was not successful. – Tomalak May 02 '22 at 06:49
-
1Hello I already ran the response.status_code which resulted in Response[200], so i know it's successful – Elizabeth Hudson May 02 '22 at 08:31
1 Answers
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
-
1You 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