runtime-errorout-of-memoryosmnxoverpass-api

osmnx: how to access log messages when retrieve features in python?


I would like to intercept a specific log coming from overpass api and perform a retry of the function. When using

import osmnx as ox
ox.settings.log_console = True

I see the messages i.e. :

2025-05-28 09:14:32 Resolved 'overpass-api.de' to '65.109.112.52'

2025-05-28 09:15:52 Downloaded 0.4kB from 'overpass-api.de' with status 200

2025-05-28 09:15:52 'overpass-api.de' remarked: 'runtime error: Query run out of memory using about 4838 MB of RAM.'

2025-05-28 09:15:52 Retrieved 0 elements from API in 1 request(s)

if the runtime error is present, I need to block the run and perform a retry of a function. is there a way to access this log console? This is not a return of a function of osmnx, but it is coming from the API and is a general setting. I could not find any example on the python library documentation.


Solution

  • Saving your log and fixing your memory issue can both be achieved by OSMnx's settings module.

    how to access log messages when retrieve features

    Use ox.settings.log_file to write the log to disk (and optionally read/process it further).

    runtime error: Query run out of memory using about 4838 MB of RAM

    Use ox.settings.overpass_memory to configure the server's memory allocation or ox.settings.max_query_area_size to subdivide large queries into smaller sub-queries for the server to handle it better.

    If you are indeed getting 0 elements back from the API, you should receive an InsufficientResponseError, which you can catch/handle.