hsnam95 / class2022Spring

130 stars 21 forks source link

jsondecodeerror #2

Closed won21 closed 2 years ago

won21 commented 2 years ago

안녕하세요, 영어음성학응용 강의 수강중인 2020130892 이원입니다. 과제 중 질문이 생겨 질문드리겠습니다!

강의해주신대로 오픈 API의 URL을 가져와서 입력한 후 r=response.json() r 과 같이 실행하자 오류가 발생했습니다. 오류는 다음과 같습니다.

`JSONDecodeError Traceback (most recent call last) in () ----> 1 r=response.json() 2 r

3 frames /usr/local/lib/python3.7/dist-packages/requests/models.py in json(self, kwargs) 896 # used. 897 pass --> 898 return complexjson.loads(self.text, kwargs) 899 900 @property

/usr/lib/python3.7/json/init.py in loads(s, encoding, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw) 346 parse_int is None and parse_float is None and 347 parse_constant is None and object_pairs_hook is None and not kw): --> 348 return _default_decoder.decode(s) 349 if cls is None: 350 cls = JSONDecoder

/usr/lib/python3.7/json/decoder.py in decode(self, s, _w) 335 336 """ --> 337 obj, end = self.raw_decode(s, idx=_w(s, 0).end()) 338 end = _w(s, end).end() 339 if end != len(s):

/usr/lib/python3.7/json/decoder.py in raw_decode(self, s, idx) 353 obj, end = self.scan_once(s, idx) 354 except StopIteration as err: --> 355 raise JSONDecodeError("Expecting value", s, err.value) from None 356 return obj, end

JSONDecodeError: Expecting value: line 1 column 1 (char 0)`

-요청메세지:(http://apis.data.go.kr/B552061/AccidentDeath/getRestTrafficAccidentDeath?ServiceKey=서비스키&searchYear=2019&siDo=1100&guGun=1116&numOfRows=20&pageNo=1)

-decoding, encoding 인증키 모두 오류가 발생하고 출력은 정상으로 확인했습니다

해결방안과 문제발생 원인을 알고 싶습니다. 감사합니다!

subin9 commented 2 years ago

이것만으로는 오류의 원인을 알기가 힘듭니다. 높은 확률로 parameter 작성 시 오류가 있었을 것 같습니다. full code를 올려주시면 확인해보겠습니다.

won21 commented 2 years ago

!pip install gradio import gradio as gr import requests import pandas as pd URL=('http://apis.data.go.kr/B552061/AccidentDeath/' 'getRestTrafficAccidentDeath?' '&ServiceKey=jXFdT16d5oT780rXsQYMwH%2BpfukLT5OV6fH6ELcLJv3uwOyNhfKRgWxrJCAize6wLtCEG9TOaDh9wNTh08oYiw%3D%3D' '&searchYear=2019' '&siDo=1100' '&guGun=1116' '&numOfRows=20' '&pageNo=1') response=requests.get(URL) r=response.json() r

감사합니다!

subin9 commented 2 years ago

네이버 메일 앱에서 보냈습니다. 날짜: 2022.03.31 오후 10:16:36 (GMT+09:00) 제목: Re: [hsnam95/class2022Spring] jsondecodeerror (Issue #2)

!pip install gradio import gradio as gr import requests import pandas as pd URL=('http://apis.data.go.kr/B552061/AccidentDeath/' 'getRestTrafficAccidentDeath?' '&ServiceKey=jXFdT16d5oT780rXsQYMwH%2BpfukLT5OV6fH6ELcLJv3uwOyNhfKRgWxrJCAize6wLtCEG9TOaDh9wNTh08oYiw%3D%3D' '&searchYear=2019' '&siDo=1100' '&guGun=1116' '&numOfRows=20' '&pageNo=1') response=requests.get(URL) r=response.json() r 감사합니다! — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>

hsnam95 commented 2 years ago

&type=json 을 빠뜨렸네요

won21 commented 2 years ago

감사합니다!