[英]JSONDecodeError: Expecting value: line 1 column 1 (char 0) in python
[英]JSONDecodeError: Expecting value: line 6 column 1 (char 5)
我不知道我做錯了什么,但這是我為“獲取數據”請求獲得的回溯。 使用 Python 3.6/Jupyter。 任何幫助是極大的贊賞:
JSONDecodeError Traceback (most recent call last)
<ipython-input-18-58ecd65ea1d8> in <module>
1 # get philadelphia data
----> 2 phila_data=get_phila_data()
<ipython-input-17-3e885b099096> in get_phila_data()
2 url='https://github.com/tjh7019/Capstone_Week_4/blob/master/incidents_2019.csv'
3 response = requests.get(url)
----> 4 return response .json()
5 # all data is present in features label
6 features=resp['features']
/opt/conda/envs/Python36/lib/python3.6/site-packages/requests/models.py in json(self,
**kwargs)
895 # used.
896 pass
--> 897 return complexjson.loads(self.text, **kwargs)
898
899 @property
/opt/conda/envs/Python36/lib/python3.6/json/__init__.py in loads(s, encoding, cls,
object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
352 parse_int is None and parse_float is None and
353 parse_constant is None and object_pairs_hook is None and not kw):
--> 354 return _default_decoder.decode(s)
355 if cls is None:
356 cls = JSONDecoder
/opt/conda/envs/Python36/lib/python3.6/json/decoder.py in decode(self, s, _w)
337
338 """
--> 339 obj, end = self.raw_decode(s, idx=_w(s, 0).end())
340 end = _w(s, end).end()
341 if end != len(s):
/opt/conda/envs/Python36/lib/python3.6/json/decoder.py in raw_decode(self, s, idx)
355 obj, end = self.scan_once(s, idx)
356 except StopIteration as err:
--> 357 raise JSONDecodeError("Expecting value", s, err.value) from None
358 return obj, end
JSONDecodeError: Expecting value: line 6 column 1 (char 5)
如有必要,我可以發送 .csv; 我只是不太確定從哪里開始解決這個問題。
您正在向服務器發出請求,響應是文本/HTML。 Requests 庫中的 .json() 旨在將 JSON 轉換為字典,由於未收到 JSON,您會收到解碼錯誤。
看看 .json 文檔: https : //requests.readthedocs.io/en/master/user/quickstart/#json-response-content
在您的情況下,您可以使用來自 GitHub 的原始鏈接來獲取 .csv 的內容
https://raw.githubusercontent.com/tjh7019/Capstone_Week_4/master/incidents_2019.csv
獲得內容后,您可以將其加載為 CSV。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.