I am trying to copy an item from one portal to another. I've written about the use case in another question.
I have some code like this. Forget about my use case above. Here I am simply trying to add a item to a folder and then publish it.
item_properties = {
'title': itemTitle,
'type': 'File Geodatabase',
'description': item.description,
'accessInformation': item.accessInformation,
'licenseInfo': item.licenseInfo,
'overwrite': True
}
# to ensure no prev items can exist in same spot
folder_name = f"_testing_{item_properties['title']}_{str(uuid.uuid4())[:4]}"
# create new folder to hold
new_folder = trg.content.folders.create(folder_name)
fgd = new_folder.add(item_properties=item_properties, file=download_result).result()
targetService = fgd.publish(overwrite=True)
I get the error. It appears to be associated with Publish. It is impossible for me to parse what it means:
Exception('Unable to Add messages Job Event\nUnable to Add messages Job Event\n(Error Code: 500)'),)
Stack trace
targetService = fgd.publish(overwrite=True)
--- Logging error ---
Traceback (most recent call last):
File "C:\Users\me\code\source\repos\arcgis-cloner\src\service_app.py", line 105, in copy_layer_to_folder
targetService = fgd.publish(overwrite=True)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\me\.virtualenvs\arcgis-cloner-pO5T1BLr\Lib\site-packages\arcgis\gis\__init__.py", line 16273, in publish
return job.result()
^^^^^^^^^^^^
File "C:\Python312\Lib\concurrent\futures\_base.py", line 449, in result
return self.__get_result()
^^^^^^^^^^^^^^^^^^^
File "C:\Python312\Lib\concurrent\futures\_base.py", line 401, in __get_result
raise self._exception
File "C:\Python312\Lib\concurrent\futures\thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\me\.virtualenvs\arcgis-cloner-pO5T1BLr\Lib\site-packages\arcgis\gis\__init__.py", line 16550, in _publish
ret = self._portal.publish_item(
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\me\.virtualenvs\arcgis-cloner-pO5T1BLr\Lib\site-packages\arcgis\gis\_impl\_portalpy.py", line 509, in publish_item
resp = self.con.post(path, postdata, files)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\me\.virtualenvs\arcgis-cloner-pO5T1BLr\Lib\site-packages\arcgis\gis\_impl\_con\_connection.py", line 1504, in post
return self._handle_response(
^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\me\.virtualenvs\arcgis-cloner-pO5T1BLr\Lib\site-packages\arcgis\gis\_impl\_con\_connection.py", line 979, in _handle_response
self._handle_json_error(data["error"], errorcode)
File "C:\Users\me\.virtualenvs\arcgis-cloner-pO5T1BLr\Lib\site-packages\arcgis\gis\_impl\_con\_connection.py", line 1002, in _handle_json_error
raise Exception(errormessage)
Exception: Unable to Add messages Job Event
Unable to Add messages Job Event
(Error Code: 500)
If I remove the overwite=True then publish does not work at all since an unpublished version is created in the same folder during this process, and so I get the error:
Arguments: (Exception({'message': "Service name 'MyServkce' already exists for '1234abcd'"}),)
I've tried to downgrade to arcgis==2.0.0 from 2.4.0 but the error persists.
How can I solve this error?
Gave replicating this a try and my 10.9.1 portal is giving a better error:
import arcgis
import uuid
src=arcgis.GIS("https://myorg.maps.arcgis.com/", "username", "password")
dest = arcgis.GIS("pro")
my_gdb = src.content.search("TestData", item_type=arcgis.gis.ItemTypeEnum.FILE_GEODATABASE.value)[0]
download = my_gdb.download()
props = arcgis.gis.ItemProperties(title=my_gdb.title,
item_type=my_gdb.type,
description=my_gdb.description,
access_information=my_gdb.accessInformation,
license_info=my_gdb.licenseInfo)
new_folder = dest.content.folders.create(f"_testing_{my_gdb.title}_{str(uuid.uuid4())[:4]}")
new_gdb = new_folder.add(item_properties=props, file=download).result()
new_service = new_gdb.publish(overwrite=True)
I get this error on line 14: Exception: Analyze Service error: Server tool execution failed : ERROR 000800: The value is not a member of SHAPEFILE | CSV | EXCEL. Failed. (Error Code: 0). If I drop the overwrite parameter then there are no issues. I assume overwriting isn't supported for File GDBs, guess you'll have to add a check for the existing items and delete them yourself.