Python InvalidSchema with Docker On-Premise

Ive looked over similar issues, and can’t solve this issue.

The only way I know to describe my problem are the two symptoms:

Symptom 1

client = openrouteservice.Client(base_url='localhost:8080/ors')
matrix = client.distance_matrix(
    locations=head,
    profile='driving-car',
    metrics=['distance', 'duration'],
    validate=True,
)

yields

InvalidSchema: No connection adapters were found for 'localhost:8080/ors/v2/matrix/driving-car/json?'

The code works when using the web client. (key=’…’)

I have already tried 0.0.0.0 and 127.0.0.1 and various other client URL configurations to no success.

Interestingly, the url ends with a ? character, which other examples and issues do not include.

Symptom 2

localhost:8080/ors/health and localhost:8080/status show up entirely blank, but localhost:8080 does show the wildcat help page. Edit: Symptom 2 identified as user error; url was missing v2

Install info:

  • Docker Desktop install on MacOS
  • used git clone
  • added .pbf to src/main/files
  • changed ors-config.json to only have driving-car active and added pdf source, discarded ors-config-sample
  • edited docker-compose.yml to edit ORS_CONFIG and OSM_FILE
  • then cd docker, then docker-compose up

Other notes:

Logs suggest memory is fine. Last logs were all INFO [routing.RoutingProfileManager]
Got ~20 lines like WARN [extensions.ORSOSMReader] - null. Way id = XXXXXXX

Please, any assistance is valuable

Hey,

just a quick notice regarding symptom 2:
The correct addresses to query for status and health are localhost:8080/ors/v2/status and localhost:8080/ors/v2/health.

Best regards

Oh, thank you. Symptom 2 was user error, I guess. :upside_down_face:

I guess then the primary issue is with Openrouteservice-py
InvalidSchema: No connection adapters were found for ‘localhost:8080/ors/v2/matrix/driving-car/json?’

Is this the best forum, or should I create an issue on GitHub?

Thanks,
John

Confirmed same error type when using client.directions:

InvalidSchema: No connection adapters were found for ‘localhost:8080/ors/v2/directions/driving-car/json?’

Hey,

have you tried issuing a request against your instance directly, i.e. using cURL? Examples can be found in the playground.
What are the results when looking at the health-endpoint?

Best regards

Thanks for these suggestions

health endpoint shows {"status":"ready"}

http://localhost:8080/ors/v2/directions/driving-car?start=removed&end=removed
This worked, and returned a route

  'localhost:8080/ors/v2/matrix/driving-car' \
  -H 'Content-Type: application/json; charset=utf-8' \
  -H 'Accept: application/json, application/geo+json, application/gpx+xml, img/png; charset=utf-8' \
  -H 'Authorization: your-api-key' \
  -d '{"locations":[A,B,C]}'

This returned the expected 3x3 duration matrix, destination data, and metadata

The instance seems healthy, so I am guessing python is the issue? I am using Jupiter Lab at localhost:8888. I don’t know if that would affect this.

Yeah, it seems like that.

Could you paste your complete code? What pbf are you using?

Gladly, thank you.

I am using texas-latest.osm.pbf from Geofabrik Download Server

Code

I’ll have to redact specific coordinates:

import pandas as pd
import openrouteservice
from openrouteservice import convert
import json

df = pd.read_sql_query(some-sql-code-here)
# df is 384 x 21, with a 'coords' column formatted as long,lat

# at this point, I was testing if the instance works

head = df['Coords'].head().values.tolist()
head = list(map(eval, head))
# head is a list of 5 (long, lat) tuples, including A,B,C from my cURL above

client = openrouteservice.Client(base_url='localhost:8080/ors')
matrix = client.distance_matrix(
    locations=head,
    profile='driving-car',
    metrics=['distance', 'duration'],
    validate=True,
)

This is where I got the matrix endpoint error. Some of these locations may be more than 10000 meters away, but I dont think the code even got so far as to facing that error.

Directions endpoint

I also attempted the same as the directions endpoint url above:

dcoord = ((start),(end))
routes = client.directions(dcoord)

This gave me the directions endpoint error. The two locations are within the 10000 meter limit in my config.

Error text

I need the matrix endpoint for my use case, so here’s the full error

---------------------------------------------------------------------------
InvalidSchema                             Traceback (most recent call last)
<ipython-input-77-2244bc118b9d> in <module>
----> 1 matrix = client.distance_matrix(
      2     locations=head,
      3     profile='driving-car',
      4     metrics=['distance', 'duration'],
      5     validate=True,

~/opt/anaconda3/lib/python3.8/site-packages/openrouteservice/client.py in wrapper(*args, **kwargs)
    297     def wrapper(*args, **kwargs):
    298         args[0]._extra_params = kwargs.pop("extra_params", None)
--> 299         result = func(*args, **kwargs)
    300         try:
    301             del args[0]._extra_params

~/opt/anaconda3/lib/python3.8/site-packages/openrouteservice/distance_matrix.py in distance_matrix(client, locations, profile, sources, destinations, metrics, resolve_locations, units, optimized, validate, dry_run)
    114         params["optimized"] = optimized
    115 
--> 116     return client.request("/v2/matrix/" + profile + '/json', {}, post_json=params, dry_run=dry_run)

~/opt/anaconda3/lib/python3.8/site-packages/openrouteservice/client.py in request(self, url, get_params, first_request_time, retry_counter, requests_kwargs, post_json, dry_run)
    184 
    185         try:
--> 186             response = requests_method(self._base_url + authed_url,
    187                                        **final_requests_kwargs)
    188             self._req = response.request

~/opt/anaconda3/lib/python3.8/site-packages/requests/sessions.py in post(self, url, data, json, **kwargs)
    579         """
    580 
--> 581         return self.request('POST', url, data=data, json=json, **kwargs)
    582 
    583     def put(self, url, data=None, **kwargs):

~/opt/anaconda3/lib/python3.8/site-packages/requests/sessions.py in request(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json)
    531         }
    532         send_kwargs.update(settings)
--> 533         resp = self.send(prep, **send_kwargs)
    534 
    535         return resp

~/opt/anaconda3/lib/python3.8/site-packages/requests/sessions.py in send(self, request, **kwargs)
    638 
    639         # Get the appropriate adapter to use
--> 640         adapter = self.get_adapter(url=request.url)
    641 
    642         # Start time (approximately) of the request

~/opt/anaconda3/lib/python3.8/site-packages/requests/sessions.py in get_adapter(self, url)
    729 
    730         # Nothing matches :-/
--> 731         raise InvalidSchema("No connection adapters were found for '%s'" % url)
    732 
    733     def close(self):

InvalidSchema: No connection adapters were found for 'localhost:8080/ors/v2/matrix/driving-car/json?'

Hi @SaliusTripe,

python might be a bit picky with omitting the http:// part of the url.

Did you already try the combinations mentioned here ?:

Best regards

Thanks for this suggestion

I had previously tried http://, and got “maximum retries” failures. I attempted ~10 different client URL combinations, half with http://

Somehow, attempting to add http:// just now worked! The only thing I can speculate fixing it would perhaps be the CLI cURL or the direct URL query. It may also have been

I’m not super confident the issue will not recur, but it seems fixed for now. Thank you!

Resolving code change:
client = openrouteservice.Client(base_url='localhost:8080/ors')
vvv changed to vvv
client = openrouteservice.Client(base_url='http://localhost:8080/ors')

Here’s some of the recent docker log, that may be meaningful to someone:

26-Jan-2022 14:09:25.092 INFO [http-nio-8080-exec-3] org.apache.coyote.http11.Http11Processor.service Error parsing HTTP request header

 Note: further occurrences of HTTP request parsing errors will be logged at DEBUG level.

java.lang.IllegalArgumentException: Invalid character found in method name [0x160x030x010x01J0x010x000x01F0x030x030xfdW0xfd0x890xf90x7f0xddu0x1fi)0xef0xc80xfc0xfe0x08!u0xc40x930x910x1fS0x8d0xe5x0xe00xa90xcbtu* ]. HTTP method names must be tokens

at org.apache.coyote.http11.Http11InputBuffer.parseRequestLine(Http11InputBuffer.java:434)

at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:511)

at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)

at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:831)

at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1651)

at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)

at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)

at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)

at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)

at java.base/java.lang.Thread.run(Thread.java:829)

26 Jan 14:32:10 INFO [util.SystemMessage] - SystemMessage loaded 0 messages.

26-Jan-2022 16:10:39.355 INFO [http-nio-8080-exec-4] org.apache.coyote.http11.Http11Processor.service Error parsing HTTP request header

 Note: further occurrences of HTTP request parsing errors will be logged at DEBUG level.

java.lang.IllegalArgumentException: Invalid character found in method name [INFO0x0a...]. HTTP method names must be tokens

at org.apache.coyote.http11.Http11InputBuffer.parseRequestLine(Http11InputBuffer.java:434)

at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:511)

at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)

at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:831)

at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1651)

at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)

at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)

at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)

at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)

at java.base/java.lang.Thread.run(Thread.java:829)