JSON 处理:[Errno 36] 文件名太长

JSON Handling: [Errno 36] File name too long

正在尝试从 Web 获取 geojson 文件以获取 folium choropleth 地图。

req = requests.get('https://raw.githubusercontent.com/python-visualization/folium/master/examples/data/world-countries.json')
req = req.text
geofile = json.load(open(req))

print(geofile)

但是在上面的代码片段中得到以下回溯:

OSError                                   Traceback (most recent call last)
<ipython-input-11-0a17bd75da0e> in <module>
      6 req = requests.get('https://raw.githubusercontent.com/python-visualization/folium/master/examples/data/world-countries.json')
      7 req = req.text
----> 8 geofile = json.load(open(req))
      9 
     10 print(geofile)

OSError: [Errno 36] File name too long:

不确定为什么需要 open 任何东西...只要阅读文档就足以知道如何提出请求 https://2.python-requests.org/en/master/

result = req.get("https://raw.githubusercontent.com/python-visualization/folium/master/examples/data/world-countries.json")
data = result.json()
print(data)