편집 기록

편집 기록
  • 프로필 nowp님의 편집
    날짜2019.11.21

    python JSONDecodeError 에러.. 도움이 시급합니다 ㅜㅜ


    안녕하세요, json 파싱관련 코드인데, 에러가 왜 나오는지 모르겠습니다. 도움을 요청드립니다.

    코드내용

    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)
    

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

  • 프로필 알 수 없는 사용자님의 편집
    날짜2019.11.20

    python JSONDecodeError 에러.. 도움이 시급합니다 ㅜㅜ


    안녕하세요, json 파싱관련 코드인데, 에러가 왜 나오는지 모르겠습니다. 도움을 요청드립니다.

    코드내용

    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 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)