I have to change my script for downloading feature layers from webmaps from AGOL due to the most recent update in September 2024 which changed the arcgis.mapping and arcgis.widgets into a new arcgis.map module. As a result it also changed the function WebMap() to Map() and this is where my error lies.
I am following the steps in this link and this link but neither are working. I have tried to search for my webmap by name and by id and input it to the new functionality of Map(item=my_result) but everytime I do, I get a huge result of errors. I can post the entire file is needed. Can anyone help with what I am doing wrong or what the new methodology is please?
pydantic_core._pydantic_core.ValidationError: 568 validation errors for Webmap
Here is some of the outputs for the error list, the list goes on for 1715 lines.
webmapobj = Map(item=wm_result1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\site-packages\arcgis\map\map_widget.py", line 254, in __init__
self._setup_webmap_properties(item)
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\site-packages\arcgis\map\map_widget.py", line 402, in _setup_webmap_properties
self._webmap = ws.Webmap(**data)
^^^^^^^^^^^^^^^^^
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\site-packages\pydantic\main.py", line 164, in __init__
__pydantic_self__.__pydantic_validator__.validate_python(data, self_instance=__pydantic_self__)
pydantic_core._pydantic_core.ValidationError: 568 validation errors for Webmap
operationalLayers.1.AnnotationLayerArcGISAnnotationLayer.layerDefinition.drawingInfo.renderer
Field required [type=missing, input_value={'labelingInfo': [{'label...fset': 0, 'angle': 0}}]}, input_type=dict]
For further information visit https://errors.pydantic.dev/2.4/v/missing
operationalLayers.1.AnnotationLayerArcGISAnnotationLayer.layerType
Input should be 'ArcGISAnnotationLayer' [type=literal_error, input_value='ArcGISFeatureLayer', input_type=str]
For further information visit https://errors.pydantic.dev/2.4/v/literal_error
operationalLayers.1.CatalogLayerCatalogLayer.layerDefinition.drawingInfo.renderer
Field required [type=missing, input_value={'labelingInfo': [{'label...fset': 0, 'angle': 0}}]}, input_type=dict]
For further information visit https://errors.pydantic.dev/2.4/v/missing
operationalLayers.1.CatalogLayerCatalogLayer.layerType
Input should be 'CatalogLayer' [type=literal_error, input_value='ArcGISFeatureLayer', input_type=str]
For further information visit https://errors.pydantic.dev/2.4/v/literal_error
operationalLayers.1.CSVLayerCSV.layerDefinition.drawingInfo.renderer
Field required [type=missing, input_value={'labelingInfo': [{'label...fset': 0, 'angle': 0}}]}, input_type=dict]
For further information visit https://errors.pydantic.dev/2.4/v/missing
operationalLayers.1.CSVLayerCSV.layerType
Input should be 'CSV' [type=literal_error, input_value='ArcGISFeatureLayer', input_type=str]
For further information visit https://errors.pydantic.dev/2.4/v/literal_error
operationalLayers.1.DimensionLayerArcGISDimensionLayer.layerDefinition.drawingInfo.renderer
Field required [type=missing, input_value={'labelingInfo': [{'label...fset': 0, 'angle': 0}}]}, input_type=dict]
Hi @OrvilleMcLean,
I've used the Web Map's JSON before to get the layers/tables. Below is a snippet your could use to download feature services/hosted tables from a web map.
import arcpy
from arcgis.gis import GIS
# Variables
username = 'jskinner_rats'
password = '********'
webMapID = '50223959653f40b8bb097bd0fda7994a'
outputGDB = r'C:\temp\python\test.gdb'
# Environment Variables
arcpy.env.overwriteOutput = True
# Connect to AGOL
gis = GIS('https://www.arcgis.com', username, password)
arcpy.SignInToPortal('https://www.arcgis.com', username, password)
# Get feature service and table URLs
operationalLayers = []
operationalTables = []
webMap = gis.content.get(webMapID)
webMapJSON = webMap.get_data(try_json=True)
try:
for layer in webMapJSON['operationalLayers']:
if layer['layerType'] == 'GroupLayer':
for groupLyr in layer['layers']:
operationalLayers.append(groupLyr['url'])
else:
operationalLayers.append(layer['url'])
for table in webMapJSON['tables']:
operationalTables.append(table['url'])
except KeyError:
pass
# Export Feature Services/Tables
if len(operationalLayers) > 0:
for layer in operationalLayers:
print(f"Exporting {layer}")
arcpy.ExportFeatures_conversion(layer, outputGDB + '\\' + layer.split('/')[-3])
if len(operationalTables) > 0:
for table in operationalTables:
print(f"Exporting {table}")
arcpy.ExportTable_conversion(table, outputGDB + '\\' + table.split('/')[-3])
Thanks @JakeSkinner for that reply but I was hoping to not have to change my original script too much to get it to work. Have you used the new Map function in the arcgis.map package?
@OrvilleMcLean I was able to get the below to work:
import arcpy
from arcgis.gis import GIS
from arcgis.map import Map
# Variables
username = 'jskinner_rats'
password = '*********'
webMapID = '50223959653f40b8bb097bd0fda7994a'
outputGDB = r'C:\temp\python\test.gdb'
# Environment Variables
arcpy.env.overwriteOutput = True
# Connect to AGOL
gis = GIS('https://www.arcgis.com', username, password)
arcpy.SignInToPortal('https://www.arcgis.com', username, password)
wmItem = gis.content.get(webMapID)
webmap = Map(wmItem)
layers = webmap.content.layers
tables = webmap.content.tables
# Export Feature Services/Tables
if len(layers) > 0:
for layer in layers:
print(f"Exporting {layer}")
arcpy.ExportFeatures_conversion(layer.url, outputGDB + '\\' + layer.url.split('/')[-3])
if len(tables) > 0:
for table in tables:
print(f"Exporting {table}")
arcpy.ExportTable_conversion(table.url, outputGDB + '\\' + table.url.split('/')[-3])
Thanks @JakeSkinner I have entered my own details into your script but as soon as I run
webmap = Map(wmItem)
The script breaks and I get the errors I pasted in the original posting. Can you debug those errors as I feel that would be the most helpful.
1. Does this occur on every web map?
2. What version of the api are you running?
1. Yes on every web map. It only started breaking my script as I got a new computer and installed the latest version of everything this month i.e. after the API release in September.
2. 2.4.0
@OrvilleMcLean are you able to test any other server that has ArcGIS Pro or the ArcGIS API for Python installed?
I am experiencing the same error noted by Orville. I think it is related to the fact that my WebMap has a group layer but this could be a red herring. I have one map that succesfully works with MAP() which has no group layer. But since switching to API 2.4.0 the map with group layer causes the Validation error for WebMap in the pydantic module