Hi I am new to osmapi
and python too. I was writing a script to perform some queries using osmapi
until I got this error and the data seems to work on this link https://www.openstreetmap.org/way/77517260, and same for the xml response https://api.openstreetmap.org/api/0.6/way/77517260.
When I test for another way ID it works, but this id 77517260
doesn't, here is the following error:
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
~/.pyenv/versions/3.6.4/lib/python3.6/site-packages/osmapi/OsmApi.py in _OsmResponseToDom(self, response, tag, single)
2060 all_data = osm_dom.getElementsByTagName(tag)
-> 2061 first_element = all_data[0]
2062 except (xml.parsers.expat.ExpatError, IndexError) as e:
IndexError: list index out of range
During handling of the above exception, another exception occurred:
XmlResponseInvalidError Traceback (most recent call last)
<ipython-input-20-79d93245d84a> in <module>
----> 1 way = api.NodeWays(77517260)
~/.pyenv/versions/3.6.4/lib/python3.6/site-packages/osmapi/OsmApi.py in NodeWays(self, NodeId)
513 uri = "/api/0.6/node/%d/ways" % NodeId
514 data = self._get(uri)
--> 515 ways = self._OsmResponseToDom(data, tag="way")
516 result = []
517 for way in ways:
~/.pyenv/versions/3.6.4/lib/python3.6/site-packages/osmapi/OsmApi.py in _OsmResponseToDom(self, response, tag, single)
2062 except (xml.parsers.expat.ExpatError, IndexError) as e:
2063 raise XmlResponseInvalidError(
-> 2064 "The XML response from the OSM API is invalid: %r" % e
2065 )
2066
XmlResponseInvalidError: The XML response from the OSM API is invalid: IndexError('list index out of range',)
my python code:
import osmapi as osm
api = osm.OsmApi()
way = api.NodeWays(77517260)
First - you should pass url and credentials in constructor:
api = osm.OsmApi(api="https://api.openstreetmap.org", username="username", password="secret")
Next -api/0.6/way/{id}
- maybe you are looking for WayGet
method.
Code:
import osmapi as osm
api = osm.OsmApi(api="https://api.openstreetmap.org", username="username", password="secret")
way = api.WayGet(77517260)