5

I am using the python library OSMnx, and it sends out a request to nomatim.openstreetmap.org in order to generate and load a map that is then used to create a network. However, when I try and run this over a VPN or at the office, I get this:

File "C:\ProgramData\Anaconda3\lib\site-packages\flask\app.py", line 1982, in wsgi_app
response = self.full_dispatch_request()
File "C:\ProgramData\Anaconda3\lib\site-packages\flask\app.py", line 1614, in full_dispatch_request
rv = self.handle_user_exception(e)
File "C:\ProgramData\Anaconda3\lib\site-packages\flask\app.py", line 1517, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "C:\ProgramData\Anaconda3\lib\site-packages\flask\_compat.py", line 33, in reraise
raise value
File "C:\ProgramData\Anaconda3\lib\site-packages\flask\app.py", line 1612, in full_dispatch_request
rv = self.dispatch_request()
File "C:\ProgramData\Anaconda3\lib\site-packages\flask\app.py", line 1598, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "C:\ProgramData\Anaconda3\lib\site-packages\dash\dash.py", line 551, in dispatch
return self.callback_map[target_id]['callback'](*args)
File "C:\ProgramData\Anaconda3\lib\site-packages\dash\dash.py", line 508, in add_context
output_value = func(*args, **kwargs)
File "OSMnxTest.py", line 125, in createNetwork
gdf = ox.gdf_from_place(location)
File "C:\ProgramData\Anaconda3\lib\site-packages\osmnx\core.py", line 414, in gdf_from_place
data = osm_polygon_download(query, limit=which_result)
File "C:\ProgramData\Anaconda3\lib\site-packages\osmnx\core.py", line 382, in osm_polygon_download
response_json = nominatim_request(params=params, timeout=30)
File "C:\ProgramData\Anaconda3\lib\site-packages\osmnx\core.py", line 238, in nominatim_request
response = requests.get(url, params=params, timeout=timeout, headers=get_http_headers())
File "C:\ProgramData\Anaconda3\lib\site-packages\requests\api.py", line 72, in get
return request('get', url, params=params, **kwargs)
File "C:\ProgramData\Anaconda3\lib\site-packages\requests\api.py", line 58, in request
return session.request(method=method, url=url, **kwargs)
File "C:\ProgramData\Anaconda3\lib\site-packages\requests\sessions.py", line 508, in request
resp = self.send(prep, **send_kwargs)
File "C:\ProgramData\Anaconda3\lib\site-packages\requests\sessions.py", line 618, in send
r = adapter.send(request, **kwargs)
File "C:\ProgramData\Anaconda3\lib\site-packages\requests\adapters.py", line 506, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='nominatim.openstreetmap.org', port=443): Max retries exceeded with url: /search?format=json&limit=1&dedupe=0&polygon_geojson=1&q=mclean%2Cva%2Cusa (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'ssl3_get_server_certificate', 'certificate verify failed')],)",),))

I would like to implement a fix within the script that I'm creating, and I'm aware of the dangers of disabling peer verification for certificates, so I just want to set the ssl_verify argument false for all queries that I send through this library. How can I go about doing that?

Charles Bushrow
  • 437
  • 4
  • 12
  • 1
    you have to pull requests with param verify set to false. try to open C:\ProgramData\Anaconda3\lib\site-packages\osmnx\core.py and in line 238 replace with response = requests.get(url, params=params, timeout=timeout, headers=get_http_headers(), verify = False) – Lupanoide Feb 21 '18 at 15:49
  • This works, but I am trying to avoid changing the modules within the library because I don't want to have to change it every time I update the library or use it on a different computer. Instead, I'm looking for something I can do within my script – Charles Bushrow Feb 21 '18 at 16:10
  • Did you manage to find solution? Thsnks! Coincidentally, I run into the same problem with osmnx. – agronskiy Jan 11 '21 at 19:25
  • @agronskiy , @Lupanoide 's response is the best approach I can think of, looking back on it. There is no way to set SSL verification to false by passing in an argument to the `gdf_from_place` function, so you have to change the actual request syntax in `\lib\site-packages\osmnx\core.py` file. Alternatively, you can reach out to your VPN provider, company, or ISP, and make sure that all your certificates are set up correctly and that would likely fix the issue. – Charles Bushrow Jan 12 '21 at 20:15
  • We have recently added functionality to OSMnx to allow users to override requests' parameters to resolve issues such as this. This will appear in the next release or you can install the main branch from Github today to use the latest functionality in the meantime. – gboeing Aug 16 '21 at 16:17

1 Answers1

0

OSMnx can now point to a local certificate file or override requests' parameters like auth, cert, verify, and proxies via the ox.config() function.

gboeing
  • 5,691
  • 2
  • 15
  • 41