arcgis-python-api
arcgis-python-api copied to clipboard
Unable to add a new geojson file with error item already exists but no existing item can be seen
Describe the bug I'm getting an item already exists error when attempting to add a geojson file but not such existing item can be found when searching or when inspecting the arcgis web app.
To Reproduce Steps to reproduce the behavior:
import io
from arcgis.gis import GIS
import keyring
#keyring.set_password("arcgis", "username", "password")
credentials = keyring.get_credential("arcgis", None)
gis = GIS("https://madeupname.maps.arcgis.com/", username=credentials.username, password=credentials.password)
with open('./western_australia.geojson', 'rb') as file:
geojson_data = io.BytesIO(file.read())
item_properties = {
"fileName": "western_australia.geojson",
"title": "Western Australia",
"type": "GeoJson",
"tags": "geojson, arcgis"
}
geojson_item = gis.content.add(item_properties, data=geojson_data)
error:
---------------------------------------------------------------------------
Exception Traceback (most recent call last)
Cell In[6], line 1
----> 1 geojson_item = gis.content.add(item_properties, data=geojson_data)
File ~\miniconda3\envs\arcgis\lib\site-packages\arcgis\gis\__init__.py:6837, in ContentManager.add(self, item_properties, data, thumbnail, metadata, owner, folder, item_id, **kwargs)
6835 if "text" in kwargs:
6836 item_properties["text"] = kwargs.pop("text", None)
-> 6837 itemid = self._portal.add_item(
6838 item_properties,
6839 data,
6840 thumbnail,
6841 metadata,
6842 owner_name,
6843 folder,
6844 )
6846 if itemid is not None:
6847 item = Item(self._gis, itemid)
File ~\miniconda3\envs\arcgis\lib\site-packages\arcgis\gis\_impl\_portalpy.py:438, in Portal.add_item(self, item_properties, data, thumbnail, metadata, owner, folder)
436 resp = self.con.post_multipart(path, postdata, files)
437 else:
--> 438 resp = self.con.post(path, postdata, files)
439 if resp and resp.get("success"):
440 return resp["id"]
File ~\miniconda3\envs\arcgis\lib\site-packages\arcgis\gis\_impl\_con\_connection.py:1524, in Connection.post(self, path, params, files, **kwargs)
1522 if return_raw_response:
1523 return resp
-> 1524 return self._handle_response(
1525 resp=resp,
1526 out_path=out_path,
1527 file_name=file_name,
1528 try_json=try_json,
1529 force_bytes=kwargs.pop("force_bytes", False),
1530 )
File ~\miniconda3\envs\arcgis\lib\site-packages\arcgis\gis\_impl\_con\_connection.py:1000, in Connection._handle_response(self, resp, file_name, out_path, try_json, force_bytes, ignore_error_key)
998 return data
999 errorcode = data["error"]["code"] if "code" in data["error"] else 0
-> 1000 self._handle_json_error(data["error"], errorcode)
1001 return data
1002 else:
File ~\miniconda3\envs\arcgis\lib\site-packages\arcgis\gis\_impl\_con\_connection.py:1023, in Connection._handle_json_error(self, error, errorcode)
1020 # _log.error(errordetail)
1022 errormessage = errormessage + "\n(Error Code: " + str(errorcode) + ")"
-> 1023 raise Exception(errormessage)
Exception: Item 'western_australia.geojson' already exists.
(Error Code: 409)
Screenshots
Expected behavior I expect to be able to add a file that shouldn't already exist (I tried setting an overwrite argument that was mentioned in the docs but that didn't help)
Platform (please complete the following information):
- OS: Windows 11 Pro 22H2 22621.2428
- Browser Vivaldi
- Python API Version 2.2.0
Additional context I had successfully run the above code before (manually deleting the geojson file in arcgis.com web app). One time I ran it though and the add command gave a different error (which I unfortunately didn't capture) so maybe it partly created the geojson file but in a bad way so that I can't see it by searching for it or by looking in the web app. I've tried restarting my Jupyter kernel but I consistently get this error. I tried using the overwrite keyword argument in the item_properties when calling add (and also tried setting overwrite as a normal keyword argument when calling add but none of those attempts has worked)
@jyaistMap Do you know of a fix for this?