Search code examples
c#escapingopenstreetmaprestsharpoverpass-api

400 from Overpass API with c# (RestSharp) but not from Python (urllib)


I'm doing a query to the Overpass API which is running on a local server. I'm doing the following query from C#:

/api/interpreter?[out:json];way(around:1000,-33.933,18.4347)[amenity][name];(._;>;);out;

and it returns a 400.

I do the same call using python and it returns what I expect (namely all ways which have "amenity" and "name" tags, together with all associated nodes).

I can confirm that when the call is done from C# (using the RestSharp library) the API "sees" the ecape character "%3E" in the place of ">" whereas it "sees" ">" when the call is done from python. Here are the two calls as recorded in the apache log:

"GET /api/interpreter?[out:json];way(around:1000,-33.933,18.4347)[amenity][name];(._;>;);out; HTTP/1.1" 200 20878 "-" "Python-urllib/3.5"
"GET /api/interpreter?[out:json];way(around:1000,-33.933,18.4347)[amenity][name];(._;%3E;);out; HTTP/1.1" 400 987 "-" "RestSharp/105.2.3.0"

As you can see the calls are identical except for that character. Presumably the problem is caused by this character. However, I have a different example of a call using this character that succeeds:

GET /api/interpreter?data=[bbox][out:json];way[highway=primary];(._;%3E;);out;&bbox=27.8539696457985,-33.0194661675922,27.9045061954916,-33.0053817324078 HTTP/1.1" 200 6037 "-" "RestSharp/105.2.3.0"

What is going on here? Is the character causing the 400 or is it something else?


Solution

  • You forgot the data= parameter in your very first example, which is required to along with your query. Here's the corrected URL which works for the public instance:

    http://overpass-api.de//api/interpreter?data=[out:json];way(around:1000,-33.933,18.4347)[amenity][name];(._;%3E;);out;

    Without this parameter, you get the following error text as HTML, and - you might have already guessed it - an HTTP 400 return code:

    Error: line 1: parse error: Unknown type "%"

    Error: line 1: parse error: An empty query is not allowed

    Error: line 1: parse error: ';' or ')' expected - '3' found.