Select to view content in your preferred language

Error when using clone_items()

742
2
04-13-2022 05:28 AM
MartinHäckel
Emerging Contributor

Hello everyone!

We have moved our subcription of ArcGIS Online from US-Server to EU-Server. The bad is, that we have to get a new subcription and account for this. As a result of this we have to clone all items from the old account to the new one.

I used this technical support article https://support.esri.com/en/technical-article/000022252

Unfortunately I get an error!

My simple code is:

from arcgis.gis import GIS

gis1 = GIS("https://arcgis.com", "", "")
gis2 = GIS("https://arcgis.com", "", "")

num_items = 250 
items = gis1.content.search(query='owner:', max_items=num_items)
items

gis2.content.clone_items(items)

I used items and num_items, because only in this way, all items were listed, otherwise there were only 13 items showed.

This is the error I get:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
/tmp/ipykernel_129/2581389438.py in <module>
      8 items
      9 
---> 10 gis2.content.clone_items(items)

/opt/conda/lib/python3.7/site-packages/arcgis/gis/__init__.py in clone_items(self, items, folder, item_extent, use_org_basemap, copy_data, copy_global_ids, search_existing_items, item_mapping, group_mapping, owner, preserve_item_id)
   6728             group_mapping,
   6729             owner_name,
-> 6730             preserve_item_id=preserve_item_id,
   6731         )
   6732         return deep_cloner.clone()

/opt/conda/lib/python3.7/site-packages/arcgis/_impl/common/_clone.py in __init__(self, target, items, folder, item_extent, service_extent, use_org_basemap, copy_data, copy_global_ids, search_existing_items, item_mapping, group_mapping, owner, preserve_item_id)
    106         self._temp_dir = tempfile.TemporaryDirectory()
    107         # parse the config and get values
--> 108         self._create_graph()
    109         self._cloned_items = []
    110 

/opt/conda/lib/python3.7/site-packages/arcgis/_impl/common/_clone.py in _create_graph(self)
    118             user = self.target.users.me
    119             # Get the definitions associated with the item
--> 120             self._get_item_definitions(item)
    121 
    122             # Test if the user has the correct privileges to create the items requested

/opt/conda/lib/python3.7/site-packages/arcgis/_impl/common/_clone.py in _get_item_definitions(self, item)
    326                 except RuntimeError:
    327                     raise
--> 328                 item_definition.add_child(self._get_item_definitions(webmap))
    329             for layer_id in layer_ids:
    330                 try:

/opt/conda/lib/python3.7/site-packages/arcgis/_impl/common/_clone.py in _get_item_definitions(self, item)
    243 
    244         item_definition = None
--> 245         source = item._gis
    246 
    247         # Check if the item definition has already been added to the collection of item definitions

AttributeError: 'NoneType' object has no attribute '_gis'

 

What I am doing wrong here?

Thanks!

0 Kudos
2 Replies
MartinHäckel
Emerging Contributor

This is also not working:

 

from arcgis.gis import GIS

gis1 = GIS("https://arcgis.com", "", "")
gis2 = GIS("https://arcgis.com", "", "")

item = gis1.content.get("*")

gis2.content.clone_items([item])

 

AttributeError: 'NoneType' object has no attribute '_gis'
0 Kudos
MartinHäckel
Emerging Contributor

Sadly the problem could not be fixed, so I needed to clone the items one after the other.
First searching for the ID in AGO, then running the script with get and clone function.

Without much knowledge about Python I came out with this (like the clone_items function is described):

from arcgis.gis import GIS

gis1 = GIS("https://arcgis.com", "", "")
gis2 = GIS("https://arcgis.com", "", "")

a = gis1.content.get("ID")
b = gis1.content.get("ID")
c = gis1.content.get("ID")
d = gis1.content.get("ID")

gis2.content.clone_items([a, b, c, d])

This definitely could be done better, but in the end it worked for me.

But there is a function missing, that can list all the IDs of your content. This would have helped me a lot.

0 Kudos