Select to view content in your preferred language

Portal API content.add and .publish overwrite option not working

905
4
12-18-2024 02:24 PM
chris_del101
Regular Contributor

I'm trying to add a feature layer to portal and I get the error, even though I include overwrite=True:

Exception: {'message': "Service name 'myService' already exists for '123abc'"}
Arguments: (Exception('Unable to Add messages Job Event\nUnable to Add messages Job Event\n(Error Code: 500)'),)

I am including overwrite in the properties and in the function itself, just in case at least one might work, yet it does nothing. It's specified here .

The content.add problem can be overcome by either deleting the item from portal, or adding a script to do it, but the .publish one is fatal. I DO NOT have any item with that name and this error is still occurring. How do I make the overwrite param work?

 item_properties = {
        'title': itemTitle,
        'type': 'File Geodatabase',
        'description': item.description,
        'accessInformation': item.accessInformation,
        'licenseInfo': item.licenseInfo, 
        'overwrite': True
    }
fgd = trg.content.add(item_properties=item_properties, owner=username,
                                 data=download_result,  overwrite=True)
targetService = fgd.publish(overwrite=True)

 

I am not looking for a better way to do this overall, but to solve this issue. 

0 Kudos
4 Replies
JakeSkinner
Esri Esteemed Contributor

Hi @chris_del101,

What version of Enterprise and what version of the ArcGIS API for Python are you using?

0 Kudos
chris_del101
Regular Contributor

Hi @JakeSkinner, this taken from your migration tools for Pro. I am having trouble authenticating with those but the code looks useful.

Enterprise: 11.3.0

arcgis PY: 2.4.0

0 Kudos
JakeSkinner
Esri Esteemed Contributor

@chris_del101 try the following:

item_properties = {
        'title': itemTitle,
        'type': 'File Geodatabase',
        'description': item.description,
        'accessInformation': item.accessInformation,
        'licenseInfo': item.licenseInfo,
        'overwrite': True
    }
root_folder = trg.content.folders.get()
fgd = root_folder.add(item_properties=fgd_properties, file=download_result).result()
targetService = fgd.publish(overwrite=True)

Note:  The property `overwrite` is deprecated and support will be removed two releases after 2.4.0 for the item_properties.

0 Kudos
chris_del101
Regular Contributor

I tried a layer and this seemed to solve that problem, but not for long. I hit some other errors now, and they are just cryptic af.

I was able to copy a layer once, but when I tried a different layer I got this with no additional information.

result_item = item.export(itemTitle, 'File Geodatabase', wait=True)
--- Logging error ---
Traceback (most recent call last):
  File "C:\Users\me\code\source\repos\arcgis-cloner\src\service_app.py", line 66, in copy_layer_to_folder
    result_item = item.export(itemTitle, 'File Geodatabase', wait=True)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\me\.virtualenvs\arcgis-cloner-pO5T1BLr\Lib\site-packages\arcgis\gis\__init__.py", line 14038, in export      
    raise Exception("Could not export item: %s" % self.itemid)
Exception: Could not export item: 4ba901c8e2f248c6882a5b11552af741
Error exporting item 

I went back to the first item and tried it again I get this. It makes a new folder first, so it's not an issue of existing items existing

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)

Code I'm using

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)

 

0 Kudos