mvexel / overpass-api-python-wrapper

Python bindings for the OpenStreetMap Overpass API
Apache License 2.0
368 stars 90 forks source link

Duplicate semicolon inserted when query ends in semicolon and whitespace #101

Closed torfsen closed 6 years ago

torfsen commented 6 years ago

If my query string ends in a semicolon plus some whitespace then overpass adds an additional semicolon before adding the out statement. This results in a syntax error:

In [20]: api.get('node["name"="Berlin"]; ')
---------------------------------------------------------------------------
OverpassSyntaxError                       Traceback (most recent call last)
<ipython-input-20-447b86aa8161> in <module>()
----> 1 api.get('node["name"="Berlin"]; ')

~/projects/reduced-maps/venv/lib/python3.5/site-packages/overpass/api.py in get(self, query, responseformat, verbosity, build)
     64 
     65         # Get the response from Overpass
---> 66         r = self._get_from_overpass(full_query)
     67         content_type = r.headers.get('content-type')
     68 

~/projects/reduced-maps/venv/lib/python3.5/site-packages/overpass/api.py in _get_from_overpass(self, query)
    144         if self._status != 200:
    145             if self._status == 400:
--> 146                 raise OverpassSyntaxError(query)
    147             elif self._status == 429:
    148                 raise MultipleRequestsError()

OverpassSyntaxError: [out:json];node["name"="Berlin"]; ;out body;

Removing the whitespace fixes this, but it would be nice if overpass would do that automatically.

torfsen commented 6 years ago

An easy fix would be to change

https://github.com/mvexel/overpass-api-python-wrapper/blob/c8f96ff0bdc89db32b03def5a56fa06fb48fde2e/overpass/api.py#L118

into

raw_query = str(userquery).rstrip()

to remove trailing whitespace before checking for an existing semicolon.

mvexel commented 6 years ago

thanks for catching!