Failed to connect python to local OSR

Hello !

I installed open route service via docker and I failed to connect my local instance of the application to python.
Open route service seems to be ready to work, as I get these messages on my ubuntu terminal :

“[info] starting up engines, v5.27.0
[info] Threads: 4
[info] IP address: 0.0.0.0
[info] IP port: 5000
[info] http 1.1 compression handled by zlib version 1.2.11
[info] Listening on: 0.0.0.0:5000”

And here is what I wrote on python, based on the openrouteservice-py documentation found here : GitHub - GIScience/openrouteservice-py: The Python API to consume openrouteservice(s) painlessly!

import pandas as pd
import geopandas as gpd
coords=((40.45,-74.3),(41.0,-73.6)) #delimiting NYC
client=ors.Client(base_url='http://localhost/ors') 
routes = client.request(
  url='http://localhost/ors',
  post_json={
      'coordinates': coords,
      'profile': 'driving-car',
      'format': 'geojson'
  }) 

And here is the error message that I get :

ConnectionError: HTTPConnectionPool(host=‘localhost’, port=80): Max retries exceeded with url: /orshttp://localhost/ors (Caused by NewConnectionError(‘<urllib3.connection.HTTPConnection object at 0x7f4589d4c1c0>: Failed to establish a new connection: [Errno 111] Connection refused’))

Thank you in advance for your help !

Hey,

I am a bit confused by your first lines of messages, as this is not familiar to me and doesn’t look like “ors is running”-output - especially since there hasn’t been a v5.27.0 of ors. Could you check what command was giving you that output?

By default, ors using docker is running on port 8080. Your code is trying to connect to port 80, where it can’t find anything at url /ors. You’ll have to add the port to your client definition as such:

client = ors.Client(base_url=`http://localhost:8080/ors)

Best regards

1 Like

Hello,

Thanks so much for your answer !
It is strange indeed that I seem to have istalled a version of ors that does not exist. I get the message you are referring to when I run osrm-routed

As for the solution you suggested, I get the following message :

TTPConnectionPool(host=‘localhost’, port=8080): Max retries exceeded with url: /ors/v2/directions/driving-car/json (Caused by NewConnectionError(‘<urllib3.connection.HTTPConnection object at 0x7f4589e83820>: Failed to establish a new connection: [Errno 111] Connection refused’))

Is it a common error message ?

Thank you again for your help

Hi @Salma_El_Aazdoudi,

that’s the wrong backend you are running…
osrm → open source routing machine
ors → openrouteservice

maybe this plugin is still working GitHub - gojuno/osrm-py: Python client for OSRM API
or maybe there is another one.

Our py plugin can only be used with an openrouteservice backend

best regards

2 Likes

Thank you !