JSONDecodeError Expecting value line 1 column 1 char 0

0 votes

I am facing an error when decoding JSON.

Expecting value: line 1 column 1 (char 0)

The following is the code I use for the curl request. The error occurs at - return simplejson.loads(response_json). 

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

def web_fetch(self, url):
    buffer = StringIO()
    curl = pycurl.Curl()
    curl.setopt(curl.URL, url)
    curl.setopt(curl.TIMEOUT, self.timeout)
    curl.setopt(curl.WRITEFUNCTION, buffer.write)
    curl.perform()
    curl.close()
    response = buffer.getvalue().strip()
    return response

Traceback:

File "/Users/nab/Desktop/myenv2/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  111.                         response = callback(request, *callback_args, **callback_kwargs)
File "/Users/nab/Desktop/pricestore/pricemodels/views.py" in view_category
  620.     apicall=api.API().search_parts(category_id= str(categoryofpart.api_id), manufacturer = manufacturer, filter = filters, start=(catpage-1)*20, limit=20, sort_by='[["mpn","asc"]]')
File "/Users/nab/Desktop/pricestore/pricemodels/api.py" in search_parts
  176.         return simplejson.loads(response_json)
File "/Users/nab/Desktop/myenv2/lib/python2.7/site-packages/simplejson/__init__.py" in loads
  455.         return _default_decoder.decode(s)
File "/Users/nab/Desktop/myenv2/lib/python2.7/site-packages/simplejson/decoder.py" in decode
  374.         obj, end = self.raw_decode(s)
File "/Users/nab/Desktop/myenv2/lib/python2.7/site-packages/simplejson/decoder.py" in raw_decode
  393.         return self.scan_once(s, idx=_w(s, idx).end())

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


The URL I use for the API call works fine in the browser but gives this error when done through a curl request. Can someone help me solve this?

May 9, 2022 in Python by Kichu
• 19,040 points
7,297 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Python

0 votes
1 answer

1 Year Rolling mean pandas on column date

I believe this should work for you: # ...READ MORE

answered Sep 6, 2018 in Python by Priyaj
• 58,020 points
14,673 views
0 votes
1 answer

Is there a way to loop between 0 and 1 by 0.1 in python?

You can use the linespace function. It ...READ MORE

answered May 28, 2019 in Python by Olly
3,112 views
0 votes
1 answer

Enter a 1-10, each on a new line in a file - python

Try something like this: i=1 for i in range(10): ...READ MORE

answered Jun 20, 2019 in Python by Greg
692 views
0 votes
1 answer

char list from 0 to f

The simplest way would be a list ...READ MORE

answered Jul 15, 2019 in Python by SDeb
• 13,300 points
586 views
–1 vote
2 answers
0 votes
1 answer

ERROR: google-auth 1.11.0 has requirement setuptools>=40.3.0, but you'll have setuptools 39.0.1 which is incompatible.

This indicates you must update setuptools. Execute ...READ MORE

answered Jun 25, 2020 in Python by Sirajul
• 59,230 points
2,701 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,449 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP