Python JSONDecodeError. I need your help ㅜㅜ

Asked 2 years ago, Updated 2 years ago, 52 views

Hello, this is a code related to json parsing, but I don't know why the error is coming out. I ask for your help.

import requests, json

url = "http://placehold.it/350x150.png"

data = {
    "image_url":"http://placehold.it/350x150.png",
    "resized_images":True # Or true
}

headers = {'Content-type': 'application/json'}
r = requests.post(url, headers=headers, data=json.dumps(data))
print(r.json())
(base) [root@localhost python]# python example.py
Traceback (most recent call last):
  File "example.py", line 17, in <module>
    print(r.json())
  File "/root/anaconda3/lib/python3.7/site-packages/requests/models.py", line 897, in json
    return complexjson.loads(self.text, **kwargs)
  File "/root/anaconda3/lib/python3.7/json/__init__.py", line 348, in loads
    return _default_decoder.decode(s)
  File "/root/anaconda3/lib/python3.7/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/root/anaconda3/lib/python3.7/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

========================================================

jsondecodeerror

2022-09-21 16:02

1 Answers

The link below is not a json file or json content.

There is a decode error because it is not json.

http://placehold.it/350x150.png


2022-09-21 16:02

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.