. Advertisement .
..3..
. Advertisement .
..4..
I am new to programs and searching the json.decoder.jsondecode error: expecting value: line 1 column 1 (char 0) to understand it better. It seems it doesn’t work as expected when I used some suggestions before. This is the command line I use:
jsn_res = self.getJson(inputUrl)
jsn_resp = jsn_res.decode('utf-8')
return json.loads(jsn_resp)
def getJson(self, inputUrl):
pyCurl = pycurl.Curl()
IObuff = StringIO()
curl.setopt(pyCurl.WRITEFUNCTION, IObuff.write)
curl.setopt(pyCurl.TIMEOUT, self.timeout)
pyCurl.setopt(pyCurl.URL, inputUrl)
pyCurl.perform()
pyCurl.close()
outResp = IObuff.getvalue().strip()
return outResp
The error I’m getting is below:
Exception Type: JSONDecodeError at /pricemodels/2/dir/
Exception Value: Expecting value: line 1 column 1 (char 0)
Please give me the solution for this issue.
Two things i might recommend you to do better:
Remember to invoke
json.loads()
on content of the file and not the path in that JSON.This is something I believe many people do every now and again (me included).
You can check if your code returned an empty response body or catch the exception. You may have received a 204 no content response or a non 200-range status code. This is what you should check.
Note:
simplejson
library. The same library is available with Python asjson
module.simplejson
/json
.loads()
method handles UTF8 encoded data natively.pycurl
‘s API is very primitive. There are better alternatives if you don’t have a particular requirement.Either the or offer much friendlier APIs including JSON support. Replace your call with:
This won’t protect against URLs that don’t conform to HTTP standards. If you use arbirary URLs, make sure you check the Content-Type header to see if the server meant to provide JSON. And, for good measure, catch the exception.