ArcGIS API for Python: clone_items error

4723
12
03-26-2019 12:24 PM
AlanTabbernor
New Contributor

Hello,

I am trying to use clone_items for ArcGIS API for Python.  I am trying to clone a map to another AGOL folder which should copy the map and all dependent items to the specified folder.  This works for other maps in my content but it is failing for the specific map I need to copy today.  Does anyone know why this would be failing?  I get the following error(s).

Traceback (most recent call last):
File "C:\Users\xxx\AppData\Local\Programs\Python\Python37-32\lib\site-packages\arcgis\_impl\common\_clone.py", line 1913, in clone
self._add_features(new_layers, relationships, layer_field_mapping, feature_service.properties['spatialReference'])
File "C:\Users\xxx\AppData\Local\Programs\Python\Python37-32\lib\site-packages\arcgis\_impl\common\_clone.py", line 1281, in _add_features
object_id_mapping[layer_id] = {layer_features['attributes'][object_id_field] : add_results['objectId'] for i in range(0, len(layer_features))}
File "C:\Users\xxx\AppData\Local\Programs\Python\Python37-32\lib\site-packages\arcgis\_impl\common\_clone.py", line 1281, in <dictcomp>
object_id_mapping[layer_id] = {layer_features['attributes'][object_id_field] : add_results['objectId'] for i in range(0, len(layer_features))}
IndexError: list index out of range

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "r:\GIS_Warehouse\Production\Projects\CVRP\Scripts\promoteAGOL.py", line 107, in <module>
main()
File "r:\GIS_Warehouse\Production\Projects\CVRP\Scripts\promoteAGOL.py", line 92, in main
successItems = ag.content.clone_items(cloneArray, folder=promoteFolder, search_existing_items=False)
File "C:\Users\xxx\AppData\Local\Programs\Python\Python37-32\lib\site-packages\arcgis\gis\__init__.py", line 4034, in clone_items
return deep_cloner.clone()
File "C:\Users\xxx\AppData\Local\Programs\Python\Python37-32\lib\site-packages\arcgis\_impl\common\_clone.py", line 676, in clone
results = executor.submit(self._clone, executor).result()
File "C:\Users\xxx\AppData\Local\Programs\Python\Python37-32\lib\concurrent\futures\_base.py", line 432, in result
return self.__get_result()
File "C:\Users\xxx\AppData\Local\Programs\Python\Python37-32\lib\concurrent\futures\_base.py", line 384, in __get_result
raise self._exception
File "C:\Users\xxx\AppData\Local\Programs\Python\Python37-32\lib\concurrent\futures\thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "C:\Users\xxx\AppData\Local\Programs\Python\Python37-32\lib\site-packages\arcgis\_impl\common\_clone.py", line 663, in _clone
raise ex
File "C:\Users\xxx\AppData\Local\Programs\Python\Python37-32\lib\concurrent\futures\thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "C:\Users\xxx\AppData\Local\Programs\Python\Python37-32\lib\site-packages\arcgis\_impl\common\_clone.py", line 1922, in clone
raise _ItemCreateException("Failed to create {0} {1}: {2}".format(original_item['type'], original_item['title'], str(ex)), new_item)
arcgis._impl.common._clone._ItemCreateException: ('Failed to create Feature Service xxx: list index out of range', <Item title:"xxx" type:Feature Layer Collection owner:xxx>)

0 Kudos
12 Replies
DanPatterson_Retired
MVP Emeritus

are you using python 3.7 32bit?

0 Kudos
AlanTabbernor
New Contributor

Yes, I'm using Python 3.7.1 32 bit.

0 Kudos
DanPatterson_Retired
MVP Emeritus

Install and set up | ArcGIS for Developers 

you should be using the version of python that comes with the install.  Minimum python 3.5 BUT  if you are using the anaconda distribution associated with ArcGIS Pro, that is python 3.6.* 64 bit.  I am not sure whether bumping version to 3.7 but bitness down is appropriate.

0 Kudos
AlanTabbernor
New Contributor

I'm not sure I understand.  I just used pip install arcgis in order to get the API.  Is this not the correct way to install?

clone_items does work for me to clone different web maps, it just does not work for this one particular web map.  In fact my guess is that there is one particular feature layer that seems to cause issues as it references this feature layer when giving the error 'list index out of range'.

0 Kudos
DanPatterson_Retired
MVP Emeritus

https://anaconda.org/esri/arcgis 

conda install -c esri arcgis

0 Kudos
AlanTabbernor
New Contributor

Thanks for your help so far.  I tried installing anaconda (tried both 32 bit and 64 bit) and installing the arcgis api as you suggested from the anaconda prompt.  I then ran my script using the anaconda prompt but the line where I attempt to clone_items still gives me the same error.  Interestingly it references a different feature layer now but still gives me the 'list index out of range error'.  I should note that I do not currently have ArcGIS Pro installed.

0 Kudos
DanPatterson_Retired
MVP Emeritus

Oh.. that might explain it. If/when you install ArcGIS Pro, you might have a whole world of other issues because of multiple instances of python installations.  One anaconda installation provided by pro will allow you to create different environments if needed.  It will also allow you to work with arcpy and not rely on other packages to work with geometries.

I suspect someone else might want to weigh in if they have a solution to fix this situation.  My suggestion would be to uninstall everything, and install Pro so you have a pristine environment that you can manage (I don't even install arcmap)

0 Kudos
EarlMedina
Esri Regular Contributor

Hi Alan,

Let's take a step back and tell me if I'm correct:

  • You're using a standalone installation (i.e. anaconda, no Pro)
  • You're on the latest version of the API 1.6.0?

Using pip is fine, but it would probably be better to let anaconda handle package management. In any case, if you're not making use of arcpy then using a standalone installation usually simplifies matters.

A few questions:

  • Where are you cloning from and where are you cloning to - i.e., what are the source and target portals and their versions?
  • Regarding the Web Map that won't clone, what can you tell us about the services in the map? Are those ArcGIS Server services - if so, which version?
0 Kudos
AlanTabbernor
New Contributor

Hi Earl,

Yes, I'm using a standalone installation. (No Pro).  I was not using anaconda until yesterday when Dan suggested this, I was just using Python 3.7.1 and ensured I had the latest version of the API as I used "pip install arcgis upgrade" when I was first having issues.

I am just cloning from one folder in ArcGIS Online (not Portal) to another, all within "My Content".

Almost all of the services in the web map are ArcGIS Online Feature Layers.  The only one that is different is I am pulling Stamen Base Map tiles using "Add Layers from Web".

I'll just mention again that my script has worked doing this same task many times in the past.  I even tried the same thing on a different map yesterday and it worked no problem.  It is just this one map (or perhaps one of the features layers within it) that is giving the script trouble.

Thanks,

Alan

0 Kudos