metaodi / osmapi

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

Error while uploading "osmapi.OsmApi.ApiError: Request failed: 404 - Not Found - b'' #104

Closed alpertungakin closed 3 years ago

alpertungakin commented 4 years ago

I've just started to explore this API and tried to upload a "way" into OSM.

import osmapi
api = osmapi.OsmApi(api = "https://api06.dev.openstreetmap.org", username = "*******", password =******)
cs = api.ChangesetCreate()
start = api.NodeCreate({"lon":39.77188512682915,"lat":40.99645466061746,"visible":True})
stop = api.NodeCreate({"lon":39.77237597107887,"lat":40.99594855924428,"visible":True})
wayPoints = [start["id"], stop["id"]]
way = api.WayCreate({"nd":wayPoints ,"visible":True})
api.ChangesetUpload([{"type":"way","action":"create","data":way}])
api.ChangesetClose()

"way" is the my way object. After the execution, "Request failed: 404 - Not Found - b" this error occured. Am I doing something wrong or uncomplete?

metaodi commented 3 years ago

@alpertungakin sorry for not responding sooner, I'm finally looking at you issue.

There seems to be a misunderstanding regarding the ChangesetUpload method. You could either create a new way using WayCreate as sou did, but then ChangesetUpload is not needed.

If you want to use ChangesetUpload then see this snippet:

import osmapi
api = osmapi.OsmApi(api = "https://api06.dev.openstreetmap.org", username = "metaodi", password="mypassword")
cs = api.ChangesetCreate()
start = api.NodeCreate({"lon":39.77188512682915,"lat":40.99645466061746,"visible":True})
stop = api.NodeCreate({"lon":39.77237597107887,"lat":40.99594855924428,"visible":True})
wayPoints = [start["id"], stop["id"]]
way = {"id": -1, "nd":wayPoints ,"tag":{'highway': 'secondary'}}
api.ChangesetUpload([{"type":"way","action":"create","data":way}])
api.ChangesetClose()

Using this snippet, I created the following test changeset: https://api06.dev.openstreetmap.org/changeset/226137#map=19/40.99620/39.77213