python - JSON Handling: [Errno 36] File name too long
问题描述
Trying to fetch a geojson file from the web for a folium choropleth map.
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)
But getting the following traceback on the above code snippit:
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:
解决方案
Not sure why you would need open
anything... Simply readings docs is enough to know how to make requests
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)
推荐阅读
- windows - Powershell 等效于 Perl 的 $CHILD_ERROR
- c++ - boost::asio 通过 minGW64 安装
- swift - 快速进入 - 来自 json 的字典数组的麻烦
- ml.net - 将矩阵形式的测试数据加载到 ML.Net 中的数据视图中
- python - Matplotlib/Seaborn:如何在 x 轴的上边缘绘制地毯图?
- swift - ARKit 中的 FaceTracking – 如何在屏幕上显示“lookAtPoint”
- python-3.x - 类型错误:register_user() 缺少 1 个必需的位置参数:'self'
- rstudio - knitr 和 sweave 之间的转换
- javascript - 本地主机上的快速获取请求:3000 不起作用
- c++ - 如何正确打印内存中变量的地址?