Search code examples
pythonjsonfolium

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:

Solution

  • 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)