Skip to content Skip to sidebar Skip to footer

Requests Throws Json.decoder.JSONDecodeError: Expecting Value: Line 1 Column 1 (char 0)

I'm retrieving data from one of my endpoints: for index in self.indices_to_fetch: response = requests.post('http://localhost/fetch_one_image', json={'index': index}).js

Solution 1:

Change

response = requests.post('http://localhost/fetch_one_image', json={'index': index}).json()

to

response = requests.post('http://localhost/fetch_one_image', json={'index': index})

and take a look at what is actually returned.

json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

usually means something else, not JSON, was returned.


Maybe the problem is

image_name = Photo.query.filter(Photo.owner.has(User.id==id)).first()

as that actually fetches a Photo object (or perhaps even None, if the filter [in combination with .fist()] returns nothing), not only it's name. Try something like [it's just a guess, since I don't know your model structure]

image = Photo.query.filter(Photo.owner.has(User.id==id)).first()
response_obj = {'image_name': image.name}
return jsonify(response_obj), 200

Post a Comment for "Requests Throws Json.decoder.JSONDecodeError: Expecting Value: Line 1 Column 1 (char 0)"