metaodi / osmapi

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

readme example is not working #86

Closed matkoniecz closed 7 years ago

matkoniecz commented 7 years ago

I attempted to use https://github.com/metaodi/osmapi#write-to-openstreetmap

import osmapi
api = osmapi.OsmApi(api="api06.dev.openstreetmap.org", username = u"Mateusz Konieczny", password = u"XXX")
print "changeset creation started"
api.ChangesetCreate({u"comment": u"My first test"})
print api.NodeCreate({u"lon":1, u"lat":1, u"tag": {}})
api.ChangesetClose()

results in

changeset creation started
Invalid URL 'api06.dev.openstreetmap.org/api/0.6/changeset/create': No schema supplied. Perhaps you meant http://api06.dev.openstreetmap.org/api/0.6/changeset/create?
Invalid URL 'api06.dev.openstreetmap.org/api/0.6/changeset/create': No schema supplied. Perhaps you meant http://api06.dev.openstreetmap.org/api/0.6/changeset/create?
Invalid URL 'api06.dev.openstreetmap.org/api/0.6/changeset/create': No schema supplied. Perhaps you meant http://api06.dev.openstreetmap.org/api/0.6/changeset/create?
Invalid URL 'api06.dev.openstreetmap.org/api/0.6/changeset/create': No schema supplied. Perhaps you meant http://api06.dev.openstreetmap.org/api/0.6/changeset/create?
Invalid URL 'api06.dev.openstreetmap.org/api/0.6/changeset/create': No schema supplied. Perhaps you meant http://api06.dev.openstreetmap.org/api/0.6/changeset/create?
Traceback (most recent call last):
  File "generate_osm_edits.py", line 4, in <module>
    api.ChangesetCreate({u"comment": u"My first test"})
  File "/usr/local/lib/python2.7/dist-packages/osmapi/OsmApi.py", line 1275, in ChangesetCreate
    self._XmlBuild("changeset", {"tag": ChangesetTags})
  File "/usr/local/lib/python2.7/dist-packages/osmapi/OsmApi.py", line 2050, in _put
    return self._http('PUT', path, True, data, return_value=return_value)
  File "/usr/local/lib/python2.7/dist-packages/osmapi/OsmApi.py", line 2027, in _http
    "Give up after %s retries" % i
osmapi.OsmApi.MaximumRetryLimitReachedError: Give up after 5 retries

changing api to

api = osmapi.OsmApi(api="http://api06.dev.openstreetmap.org", username = u"Mateusz Konieczny", password = u"XXX")

results in

changeset creation started
Traceback (most recent call last):
  File "generate_osm_edits.py", line 4, in <module>
    api.ChangesetCreate({u"comment": u"My first test"})
  File "/usr/local/lib/python2.7/dist-packages/osmapi/OsmApi.py", line 1275, in ChangesetCreate
    self._XmlBuild("changeset", {"tag": ChangesetTags})
  File "/usr/local/lib/python2.7/dist-packages/osmapi/OsmApi.py", line 2050, in _put
    return self._http('PUT', path, True, data, return_value=return_value)
  File "/usr/local/lib/python2.7/dist-packages/osmapi/OsmApi.py", line 2010, in _http
    return_value=return_value
  File "/usr/local/lib/python2.7/dist-packages/osmapi/OsmApi.py", line 1984, in _http_request
    raise ApiError(response.status_code, response.reason, payload)
osmapi.OsmApi.ApiError: Request failed: 404 - Not Found - <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">
<html>
<body>
  <img src="/assets/osm_logo.png" style="float:left; margin:10px">
  <div style="float:left;">
    <h1>File not found</h1>  
    <p>Couldn't find a file/directory/API operation by that name on the OpenStreetMap server (HTTP 404)</p>
    <p>Feel free to <a href="http://wiki.openstreetmap.org/wiki/Contact" title="Various contact channels explained">contact</a> the OpenStreetMap community if you have found a broken link / bug. Make a note of the exact URL of your request.</p>
  </div>
</body>
</html>

changing api to

api = osmapi.OsmApi(api="http://master.apis.dev.openstreetmap.org", username = u"Mateusz Konieczny", password = u"XXX")

results in

changeset creation started
Traceback (most recent call last):
  File "generate_osm_edits.py", line 4, in <module>
    api.ChangesetCreate({u"comment": u"My first test"})
  File "/usr/local/lib/python2.7/dist-packages/osmapi/OsmApi.py", line 1275, in ChangesetCreate
    self._XmlBuild("changeset", {"tag": ChangesetTags})
  File "/usr/local/lib/python2.7/dist-packages/osmapi/OsmApi.py", line 2050, in _put
    return self._http('PUT', path, True, data, return_value=return_value)
  File "/usr/local/lib/python2.7/dist-packages/osmapi/OsmApi.py", line 2010, in _http
    return_value=return_value
  File "/usr/local/lib/python2.7/dist-packages/osmapi/OsmApi.py", line 1984, in _http_request
    raise ApiError(response.status_code, response.reason, payload)
osmapi.OsmApi.ApiError: Request failed: 400 - Bad Request - Cannot parse valid changeset from xml string . Must specify a string with one or more characters
pip2 list | grep osmapi
osmapi (1.0.2)

python2 --version
Python 2.7.12

uname -a
Linux grisznak 4.10.0-33-generic #37~16.04.1-Ubuntu SMP Fri Aug 11 14:07:24 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
matkoniecz commented 7 years ago

running tests gives me

======================================================================
ERROR: Failure: ImportError (No module named xmltodict)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/nose/loader.py", line 418, in loadTestsFromName
    addr.filename, addr.module)
  File "/usr/lib/python2.7/dist-packages/nose/importer.py", line 47, in importFromPath
    return self.importFromDir(dir_path, fqname)
  File "/usr/lib/python2.7/dist-packages/nose/importer.py", line 94, in importFromDir
    mod = load_module(part_fqname, fh, filename, desc)
  File "/home/mateusz/Desktop/tmp/osmapi/tests/changeset_tests.py", line 5, in <module>
    import xmltodict
ImportError: No module named xmltodict

----------------------------------------------------------------------
metaodi commented 7 years ago

It should include "https://", thanks for reporting this. I fixed it in #87

metaodi commented 7 years ago

btw: to run the tests, you need to install the test requirements (see https://github.com/metaodi/osmapi#development)