Large graph_from_place() request for OSMnx leading to timeout error

I am trying to extract the highways (motorway|trunk|primary) using OSMnx for China.

G = ox.graph_from_place('China', network_type = 'drive', infrastructure='way["highway"~"motorway|trunk|primary"]')

I’m getting a timeout error:

ConnectTimeout: HTTPConnectionPool(host='overpass-api.de', port=80): Max retries exceeded with url: /api/interpreter (Caused by ConnectTimeoutError(<urllib3.connection.HTTPConnection object at 0x000001D695D92A20>, 'Connection to overpass-api.de timed out. (connect timeout=10)')) HTTPConnectionPool(host='overpass-api.de', port=80): Max retries exceeded with url: /api/interpreter (Caused by ConnectTimeoutError(<urllib3.connection.HTTPConnection object at 0x000001D695D92A20>, 'Connection to overpass-api.de timed out. (connect timeout=10)'))

This is a large request so I’m not surprised it’s timing out, but I’d like to know if my request is too large or if there is a way of actually extracting this.

I’ve tried various timeouts in the ox.graph_from_place() (timeout = 10,180(default),1000,…) function but I don’t fully understand what the timeout means here. I guess what I don’t understand is the relationship between the timeout in the request and the timeout in Overpass Turbo.

Answer

ox.config(timeout=10000)will do your work. ox.config() is very handy function, and it can also be used for many other custom settings. I tried this function, but infrastructure did not support in my case. Else, my query got completed and I got results after 3 hours. I shall recommend you to use http://download.geofabrik.de/asia/china.html for such downloads. Please visit [1]: https://github.com/gboeing/osmnx/issues/151, and [2]: https://github.com/gboeing/osmnx/issues/445