【发布时间】:2021-04-17 05:27:53
【问题描述】:
我正在尝试从 github 导入特定的 json 文件
import urllib3
import json
http = urllib3.PoolManager()
url = 'https://raw.githubusercontent.com/leanhdung1994/BigData/main/fr-esr-principaux-etablissements-enseignement-superieur.json'
f = http.request('GET', url)
data = json.load(f.data)
您能否解释一下为什么会出现以下错误以及如何正确读取此文件?
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-14-cc9b55b171d7> in <module>
4 url = 'https://raw.githubusercontent.com/leanhdung1994/BigData/main/fr-esr-principaux-etablissements-enseignement-superieur.json'
5 f = http.request('GET', url)
----> 6 data = json.load(f.data)
~\anaconda3\lib\json\__init__.py in load(fp, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
291 kwarg; otherwise ``JSONDecoder`` is used.
292 """
--> 293 return loads(fp.read(),
294 cls=cls, object_hook=object_hook,
295 parse_float=parse_float, parse_int=parse_int,
AttributeError: 'bytes' object has no attribute 'read'
【问题讨论】:
标签: json python-3.x github urllib3