close

[Solved] JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Hello Guys, How are you all? Hope You all Are Fine. I am getting error JSONDecodeError: Expecting value: line 1 column 1 (char 0) when trying to decode JSON Python. So Here I am Explain to you all the possible solutions here.

Without Wasting your time, Lets start This Article to Solve This Error.

How JSONDecodeError: Expecting value: line 1 column 1 (char 0) Error Occurs ?

I am getting error JSONDecodeError: Expecting value: line 1 column 1 (char 0) when trying to decode JSON. The error happens at last line of my coyde.

json_response = self.web_fetch(url)
json_response = response_json.decode('utf-8')
return json.loads(json_response)

Above code giving error. here is my Traceback:

Exception Type: JSONDecodeError at /pricemodels/2/dir/
Exception Value: Expecting value: line 1 column 1 (char 0)

How To Solve JSONDecodeError: Expecting value: line 1 column 1 (char 0) Error ?

Question: How To Solve JSONDecodeError: Expecting value: line 1 column 1 (char 0) Error ?
Answer: To solve JSONDecodeError: Expecting value: line 1 column 1 (char 0) just try requests library. requests offers the most friendly API, including JSON support. If you can, replace your call with.

Solution 1

If possible Then, requests offer the most friendly API, including JSON support. If you can, replace your call with:

Also With the requests lib JSONDecodeError can happen when you have an http error code like 404 and try to parse the response as JSON !

import requests

return requests.get(url).json()

Solution 2

This Problem occurs In most cases your json.loads– JSONDecodeError: Expecting value: line 1 column 1 (char 0) error is due to non-JSON conforming quoting, XML/HTML output (that is, a string starting with <) and incompatible character encoding. Ultimately the error tells you that at the very first position the string already doesn’t conform to JSON. Solution Is to try replacing the quotes of the data-body:

import sys, json
struct = {}
try:
  try:
    dataform = str(response_json).strip("'<>() ").replace('\'', '\"')
    struct = json.loads(dataform)
  except:
    print repr(resonse_json)
    print sys.exc_info()

Solution 3

Please Confirm with this Debugger your response. To debug, I used:

response = requests.get(url)
logger.info(type(response))

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also Read

Leave a Comment