Hello,
I’m having a hard time getting my local instance of openrouteservice to work with openrouteservice-py. I was able to install successfully the application via docker. So, if I fire up the browser and type in the following url:
I get the expected result.
Now, following the python module instructions:
import openrouteservice
coords = ((12.18288363,45.689405109),(12.03793961,45.775061570))
client = openrouteservice.Client(base_url='http://localhost:8080/ors')
routes = client.directions(coords)
I get this error:
ConnectionError: HTTPConnectionPool(host='localhost', port=8080): Max retries exceeded with url: /ors/v2/directions/driving-car/json (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fd0f11ef6a0>: Failed to establish a new connection: [Errno 111] Connection refused'))
I can see that the endpoint in the browser request (“/ors/routes”) is different from the one searched by the python api (“/ors/v2/directions/driving-car/json”).
So, if I try the latter endpoint this way:
curl -X POST 'localhost:8080/ors/v2/directions/driving-car/json' -H 'Content-Type: application/json; charset=utf-8' -d '{"coordinates":[[12.182883635445991,45.68940510906503],[12.037939617550144,45.77506157013294]], "instructions":"false"}'
I get this message:
curl: (7) Failed to connect to localhost port 8080: Connection refused
After a bit of fiddling, I was able to get the answer from the server with this workaround (no idea why it works anyway):
curl -X POST '0.0.0.0:8080/ors/v2/directions/driving-car/json' -H 'Content-Type: application/json; charset=utf-8' -d '{"coordinates":[[12.182883635445991,45.68940510906503],[12.037939617550144,45.77506157013294]], "instructions":"false"}'
but initializing the client in the python module correspondingly has no success:
client = openrouteservice.Client(base_url='0.0.0.0:8080/ors')
routes = client.directions(coords)
In fact, it throws this exception:
InvalidSchema: No connection adapters were found for '0.0.0.0:8080/ors/v2/directions/driving-car/json?'
Ok. But then I can see the warning in the examples:
# If you did change the ORS endpoints for some reason
# you'll have to pass url and required parameters explicitly
and so I tried the following:
routes = client.request(
url='0.0.0.0:8080/ors',
post_json={
'coordinates': coords,
'profile': 'driving-car',
'format': 'geojson'
})
but got the error:
/.pyenv/versions/3.8.2/envs/maps/lib/python3.8/site-packages/openrouteservice/client.py in _urlencode_params(params)
328 # urlencode does not handle unicode strings in Python 2.
329 # Firstly, normalize the values so they get encoded correctly.
--> 330 params = [(key, _normalize_for_urlencode(val)) for key, val in params]
331 # Secondly, unquote unreserved chars which are incorrectly quoted
332 # by urllib.urlencode, causing invalid auth signatures. See GH #72
TypeError: 'NoneType' object is not iterable
The same goes for url = ‘/0.0.0.0:8080/ors’ and url = ‘/0.0.0.0:8080/ors/v2/directions/driving-car/json’
Does anybody have a clue of what I am getting wrong?
Thank you