Select to view content in your preferred language

Clone or copy webmap item

3412
6
Jump to solution
10-28-2021 02:44 AM
RichardReinicke
Frequent Contributor

Hi,

can someone tell me how I can copy or clone a "Web Map" item from my user root folder into another folder?

I have ArcGIS Pro 2.8.3 installed and arcgis API version 1.8.5 (latest I can get).

I tried

clone_results = gis.content.clone_items(items=[map_template], folder="test")


and yes, map_template is really the web map item in my root folder and "test" exists.

I get an error:

Exception Traceback (most recent call last)
~\AppData\Local\ESRI\conda\envs\arcgispro-py3-clone\lib\site-packages\arcgis\_impl\common\_clone.py in clone(self)
2423 # Add the new item
-> 2424 new_item = self._add_new_item(item_properties)
2425

~\AppData\Local\ESRI\conda\envs\arcgispro-py3-clone\lib\site-packages\arcgis\_impl\common\_clone.py in _add_new_item(self, item_properties, data)
1208
-> 1209 new_item = self.target.content.add(item_properties=item_properties, data=data, thumbnail=thumbnail, folder=self.folder, owner=self.owner)
1210 self.created_items.append(new_item)

~\AppData\Local\ESRI\conda\envs\arcgispro-py3-clone\lib\site-packages\arcgis\gis\__init__.py in add(self, item_properties, data, thumbnail, metadata, owner, folder, item_id)
4264 thumbnail, metadata,
-> 4265 owner_name, folder)
4266

~\AppData\Local\ESRI\conda\envs\arcgispro-py3-clone\lib\site-packages\arcgis\gis\_impl\_portalpy.py in add_item(self, item_properties, data, thumbnail, metadata, owner, folder)
354 path += '/addItem'
--> 355 resp = self.con.post(path, postdata, files)
356 if resp and resp.get('success'):

~\AppData\Local\ESRI\conda\envs\arcgispro-py3-clone\lib\site-packages\arcgis\gis\_impl\_con\_connection.py in post(self, path, params, files, **kwargs)
719 try_json=try_json,
--> 720 force_bytes=kwargs.pop('force_bytes', False))
721 #----------------------------------------------------------------------

~\AppData\Local\ESRI\conda\envs\arcgispro-py3-clone\lib\site-packages\arcgis\gis\_impl\_con\_connection.py in _handle_response(self, resp, file_name, out_path, try_json, force_bytes)
513 errorcode = data['error']['code'] if 'code' in data['error'] else 0
--> 514 self._handle_json_error(data['error'], errorcode)
515 return data

~\AppData\Local\ESRI\conda\envs\arcgispro-py3-clone\lib\site-packages\arcgis\gis\_impl\_con\_connection.py in _handle_json_error(self, error, errorcode)
535 errormessage = errormessage + "\n(Error Code: " + str(errorcode) +")"
--> 536 raise Exception(errormessage)
537 #----------------------------------------------------------------------

Exception: Unable to generate dependencies
Unable to generate dependencies
(Error Code: 500)

During handling of the above exception, another exception occurred:

_ItemCreateException Traceback (most recent call last)
<ipython-input-5-dd6b2e4b5b45> in <module>
100
101 # Copy template map to new item in project folder
--> 102 clone_results = gis.content.clone_items(items=[map_template], folder="test")
103
104 print(clone_results)

~\AppData\Local\ESRI\conda\envs\arcgispro-py3-clone\lib\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)
5515 owner_name = owner.username
5516 deep_cloner = clone._DeepCloner(self._gis, items, folder, wgs84_extent, service_extent, use_org_basemap, copy_data, copy_global_ids, search_existing_items, item_mapping, group_mapping, owner_name)
-> 5517 return deep_cloner.clone()
5518
5519 def bulk_update(self, itemids, properties):

~\AppData\Local\ESRI\conda\envs\arcgispro-py3-clone\lib\site-packages\arcgis\_impl\common\_clone.py in clone(self)
811 else:
812 with concurrent.futures.ThreadPoolExecutor(max_workers=20) as executor:
--> 813 results = executor.submit(self._clone, executor).result()
814 return results
815

~\AppData\Local\ESRI\conda\envs\arcgispro-py3-clone\lib\concurrent\futures\_base.py in result(self, timeout)
433 raise CancelledError()
434 elif self._state == FINISHED:
--> 435 return self.__get_result()
436 else:
437 raise TimeoutError()

~\AppData\Local\ESRI\conda\envs\arcgispro-py3-clone\lib\concurrent\futures\_base.py in __get_result(self)
382 def __get_result(self):
383 if self._exception:
--> 384 raise self._exception
385 else:
386 return self._result

~\AppData\Local\ESRI\conda\envs\arcgispro-py3-clone\lib\concurrent\futures\thread.py in run(self)
55
56 try:
---> 57 result = self.fn(*self.args, **self.kwargs)
58 except BaseException as exc:
59 self.future.set_exception(exc)

~\AppData\Local\ESRI\conda\envs\arcgispro-py3-clone\lib\site-packages\arcgis\_impl\common\_clone.py in _clone(self, excecutor)
798 if item:
799 item.delete()
--> 800 raise ex
801
802 level += 1

~\AppData\Local\ESRI\conda\envs\arcgispro-py3-clone\lib\concurrent\futures\thread.py in run(self)
55
56 try:
---> 57 result = self.fn(*self.args, **self.kwargs)
58 except BaseException as exc:
59 self.future.set_exception(exc)

~\AppData\Local\ESRI\conda\envs\arcgispro-py3-clone\lib\site-packages\arcgis\_impl\common\_clone.py in clone(self)
2429 return new_item
2430 except Exception as ex:
-> 2431 raise _ItemCreateException("Failed to create {0} {1}: {2}".format(original_item['type'], original_item['title'], str(ex)), new_item)
2432
2433

_ItemCreateException: ('Failed to create Web Map vorlage-karte: Unable to generate dependencies\nUnable to generate dependencies\n(Error Code: 500)', None)

I already reinstalled my whole ArcGIS Pro and conda/python environment, error remains.

Any ideas?

Tags (3)
0 Kudos
1 Solution

Accepted Solutions
RichardReinicke
Frequent Contributor

Okay, I found the mistake. I had an invalid layer in my template map. The invalid layer was the result of trying to create a new group layer programmatically.

Without the invalid layer there are several ways to achieve the copy webmap task. Here is one that I'm using now and which is working for me:

 

# This is my base webmap (template)
map_template = gis.content.get('some_item_id')

# Copy template to new web map item into subfolder
project_map = WebMap(map_template).save({
    "title": "project map",
    "snippet": "some description",
    "tags": "maps"}, folder="project_folder")

 

View solution in original post

0 Kudos
6 Replies
CarstenB_orsted
Occasional Contributor

 

I believe Clone_items is only for cloning items between different portals (eg. from staging to production portal). That is what I am using it for!

Maybe look into item.copy.item? I have never tried that though.

0 Kudos
RichardReinicke
Frequent Contributor

Hi @CarstenB_orsted,

I believe, you're right in this points. I came to the same conclusion when browsing online materials:

I also tested following way:

map_json = json.dumps(map_template.get_data(try_json=True))
project_map = gis.content.add({"title": "ABC", "type": "Web Map", "snippet": "ABCD", "tags": "XYZ", "text": map_json}, folder="test")



Exact same result here!

I'll also try your version as wll now.

0 Kudos
RichardReinicke
Frequent Contributor

Function item.copy_item() is not available in 1.8.5 and I dont know how I can get the latest 1.9.1 version because I'm using ArcGIS Pro environment clone and latest Pro version 2.8.3 only supports 1.8.5.

item.copy() doesn't seem to be appropriate for what I'm trying to achieve.

0 Kudos
RichardReinicke
Frequent Contributor

3. Option now
clone_results = WebMap(map_template).save({"title": "ABC", "snippet": "XYZ", "tags": "abc"}, folder="test")

Exact same result... okay it must be something else related to our portal...
I'll investigate this.

0 Kudos
RichardReinicke
Frequent Contributor

Okay all 3 approaches have the same result BUT I forgot to mention that in all three cases the web map copy get's created in the other folder only in my jupyter notebook I get the strange python error.

Portal logs looking okay. Item created successfully.

So it seems to be a communication problem between arcgis python API and the portal. Also the error is raised in _connection.py!

0 Kudos
RichardReinicke
Frequent Contributor

Okay, I found the mistake. I had an invalid layer in my template map. The invalid layer was the result of trying to create a new group layer programmatically.

Without the invalid layer there are several ways to achieve the copy webmap task. Here is one that I'm using now and which is working for me:

 

# This is my base webmap (template)
map_template = gis.content.get('some_item_id')

# Copy template to new web map item into subfolder
project_map = WebMap(map_template).save({
    "title": "project map",
    "snippet": "some description",
    "tags": "maps"}, folder="project_folder")

 

0 Kudos