'str' object has no attribute

209
3
Jump to solution
04-30-2021 03:55 PM
CherylCollins
New Contributor III

Searching through the other messages hasn't helped me with this.  I like to figure things out on my own, but I'm stumped.  I copied the deep_copy_content part below from a technical article, and only changed item.title to itemid and switched "gis" and "gis2".  Otherwise it's the same.  "gis" is my target location.

Here's what I'm seeing.  I appreciate any suggestions.

CherylCollins_0-1619823071698.png

 

 

0 Kudos
1 Solution

Accepted Solutions
AaronPulver
Esri Regular Contributor

The clone_items function takes a list of Items. It seems like you are passing in the string item ids instead.

It looks like you didn't include the code that initializes the items array so I can't tell if that's the actual issue.

Try something like:

itemid = "xxxxx"

# Fetch item from gis
item = gis.content.get(itemid)

# Clone to gis2
gis2.content.clone_items([item], copy_date=True, search_existing_items=True)

 

View solution in original post

3 Replies
AaronPulver
Esri Regular Contributor

The clone_items function takes a list of Items. It seems like you are passing in the string item ids instead.

It looks like you didn't include the code that initializes the items array so I can't tell if that's the actual issue.

Try something like:

itemid = "xxxxx"

# Fetch item from gis
item = gis.content.get(itemid)

# Clone to gis2
gis2.content.clone_items([item], copy_date=True, search_existing_items=True)

 

View solution in original post

CherylCollins
New Contributor III

Got it! What worked was adding item = before gis.content.get and replacing copy_list with [item]. I also got an error message about copy_data=True, but I just deleted that and it worked. Thanks for the help. I'm attaching the whole final script.  Tim_McGinnes also suggested part of the same answer.

0 Kudos
Tim_McGinnes
Occasional Contributor III

It looks like you may have left out a crucial line from the script  (Link) :

 

items = gis.content.get(itemid)

 

If gis is your target and gis2 is your source then it should be:

items = gis2.content.get(itemid)

 

Try the following:

 

from arcgis.gis import GIS
gis = GIS(<Put your URL here>) # Where it is going to
gis2 = GIS(<Put your URL here>) # Where it is coming from
itemid = '<Put your ID here>' # The item ID to clone
items = gis2.content.get(itemid) 
def deep_copy_content(input_list):
    for item in input_list:
        try:
            print("Cloning " + item.title)
            copy_list = []
            copy_list.append(item)
            gis.content.clone_items(copy_list, copy_data=True, search_existing_items=True)
            print("Successfully cloned " + item.title)
        except Exception as e:
            print(e)
    print("The function has completed")
deep_copy_content(items)

 

 

0 Kudos