metaodi / osmapi

Python wrapper for the OpenStreetMap API
http://osmapi.metaodi.ch/
GNU General Public License v3.0
211 stars 41 forks source link

empty notes list crashes api #137

Closed matkoniecz closed 1 year ago

matkoniecz commented 1 year ago
import osmapi
api = osmapi.OsmApi()
print(api.NotesGet(-93.8472901, 35.9763601, -80, 36.176360100000004, limit=1, closed=0))
print(api.NotesGet(-93.8472901, 35.9763601, -93.6472901, 36.176360100000004, limit=1, closed=0))

results in

[{'lon': -80.33461, 'lat': 36.0379985, 'id': '3506423', 'status': 'open', 'date_created': datetime.datetime(2023, 1, 6, 3, 4, 9), 'date_closed': None, 'comments': [{'date': datetime.datetime(2023, 1, 6, 3, 4, 9), 'action': 'opened', 'text': '1760 jonestown Rd\nBusiness office, Triad Semiconductor\n\nvia StreetComplete 50.1', 'html': '<p>1760 jonestown Rd\n<br />Business office, Triad Semiconductor</p>\n\n<p>via StreetComplete 50.1</p>', 'uid': '18189196', 'user': 'Scollywoggle'}]}]
Traceback (most recent call last):
  File "/home/mateusz/.local/lib/python3.8/site-packages/osmapi/OsmApi.py", line 2076, in _OsmResponseToDom
    first_element = all_data[0]
IndexError: list index out of range

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "test.py", line 4, in <module>
    print(api.NotesGet(-93.8472901, 35.9763601, -93.6472901, 36.176360100000004, limit=1, closed=0))
  File "/home/mateusz/.local/lib/python3.8/site-packages/osmapi/OsmApi.py", line 1599, in NotesGet
    return self.ParseNotes(data)
  File "/home/mateusz/.local/lib/python3.8/site-packages/osmapi/OsmApi.py", line 1841, in ParseNotes
    noteElements = self._OsmResponseToDom(data, tag="note")
  File "/home/mateusz/.local/lib/python3.8/site-packages/osmapi/OsmApi.py", line 2078, in _OsmResponseToDom
    raise XmlResponseInvalidError(
osmapi.OsmApi.XmlResponseInvalidError: The XML response from the OSM API is invalid: IndexError('list index out of range')

note that the first call worked - because it had some notes to return

metaodi commented 1 year ago

Thanks for this excellent report. This should be a test case, so this never happens again.