I am receiving the following error when running a Python script to update a map for one of our Operations Dashboard:
C<SPAN class="punctuation token">:</SPAN>\Users\kierc\projects\xyz xyz Extension Survey\Batch Files <SPAN class="keyword token">for</SPAN> Script Scheduling<SPAN class="operator token">></SPAN><SPAN class="string token">"C:\ArcGIS_Pro\Conda\Cloned_Envs\arcgispro-py3-subtel\python.exe"</SPAN> <SPAN class="string token">"C:\Users\kierc\projects\api\UpdateXXXXXMap.py"</SPAN>
Creating SD file
Traceback <SPAN class="punctuation token">(</SPAN>most recent call last<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
File <SPAN class="string token">"C:\Users\kierc\projects\api\UpdateXXXXXMap.py"</SPAN><SPAN class="punctuation token">,</SPAN> line <SPAN class="number token">33</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">in</SPAN> <SPAN class="operator token"><</SPAN>module<SPAN class="operator token">></SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>mp<SPAN class="punctuation token">.</SPAN>CreateWebLayerSDDraft<SPAN class="punctuation token">(</SPAN>mp<SPAN class="punctuation token">,</SPAN> sddraft<SPAN class="punctuation token">,</SPAN> sd_fs_name<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'MY_HOSTED_SERVICES'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'FEATURE_ACCESS'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="token boolean">True</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="token boolean">True</SPAN><SPAN class="punctuation token">)</SPAN>
File <SPAN class="string token">"C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\mp.py"</SPAN><SPAN class="punctuation token">,</SPAN> line <SPAN class="number token">105</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">in</SPAN> CreateWebLayerSDDraft
<SPAN class="keyword token">return</SPAN> _convertArcObjectToPythonObject<SPAN class="punctuation token">(</SPAN>arcgisscripting<SPAN class="punctuation token">.</SPAN>_mapping<SPAN class="punctuation token">.</SPAN>CreateWebLayerSDDraft<SPAN class="punctuation token">(</SPAN><SPAN class="operator token">*</SPAN>_gp_fixargs<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">[</SPAN>map_or_layers<SPAN class="punctuation token">,</SPAN> out_sddraft<SPAN class="punctuation token">,</SPAN> service_name<SPAN class="punctuation token">,</SPAN> server_type<SPAN class="punctuation token">,</SPAN> service_type<SPAN class="punctuation token">,</SPAN> folder_name<SPAN class="punctuation token">,</SPAN> overwrite_existing_service<SPAN class="punctuation token">,</SPAN> copy_data_to_server<SPAN class="punctuation token">,</SPAN> enable_editing<SPAN class="punctuation token">,</SPAN> allow_exporting<SPAN class="punctuation token">,</SPAN> enable_sync<SPAN class="punctuation token">,</SPAN> summary<SPAN class="punctuation token">,</SPAN> tags<SPAN class="punctuation token">,</SPAN> description<SPAN class="punctuation token">,</SPAN> credits<SPAN class="punctuation token">,</SPAN> use_limitations<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="token boolean">True</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
RuntimeError<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>I have X'd out the actual name of the files as there is some potentially sensitive information associated with the names, but the character counts and spacing are preserved.
Additionally, this is only an issue if I am logged out in ArcGIS Pro. However, logging in to ArcGIS Pro is not a full solution as I will need to be updating maps soon for multiple organizations. The following is the Python script I am using:
<SPAN class="keyword token">import</SPAN> arcpy
<SPAN class="keyword token">import</SPAN> os<SPAN class="punctuation token">,</SPAN> sys
<SPAN class="keyword token">from</SPAN> arcgis<SPAN class="punctuation token">.</SPAN>gis <SPAN class="keyword token">import</SPAN> GIS
<SPAN class="comment token">### Start setting variables</SPAN>
<SPAN class="comment token"># Set the path to the project</SPAN>
prjPath <SPAN class="operator token">=</SPAN> r<SPAN class="string token">'C:\Users\kierc\Documents\ArcGIS\Projects\XXXXXXXXXXXExt\XXXXXXXXXXXExt.aprx'</SPAN>
<SPAN class="comment token"># Update the following variables to match:</SPAN>
<SPAN class="comment token"># Feature service/SD name in arcgis.com, user/password of the owner account</SPAN>
sd_fs_name <SPAN class="operator token">=</SPAN> <SPAN class="string token">"xyz_xyz_Extention_Inshore_Survey_WFL1"</SPAN>
portal <SPAN class="operator token">=</SPAN> <SPAN class="string token">"http://www.arcgis.com"</SPAN> <SPAN class="comment token"># Can also reference a local portal</SPAN>
user <SPAN class="operator token">=</SPAN> <SPAN class="string token">"xyz"</SPAN>
password <SPAN class="operator token">=</SPAN> <SPAN class="string token">"xyz"</SPAN>
<SPAN class="comment token"># Set sharing options</SPAN>
shrOrg <SPAN class="operator token">=</SPAN> <SPAN class="token boolean">False</SPAN>
shrEveryone <SPAN class="operator token">=</SPAN> <SPAN class="token boolean">False</SPAN>
shrGroups <SPAN class="operator token">=</SPAN> <SPAN class="string token">""</SPAN>
<SPAN class="comment token">### End setting variables</SPAN>
<SPAN class="comment token"># Local paths to create temporary content</SPAN>
relPath <SPAN class="operator token">=</SPAN> r<SPAN class="string token">'C:\Users\kierc\projects\api\arcgistempcurrent'</SPAN>
sddraft <SPAN class="operator token">=</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN>relPath<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"CurrentUpdate.sddraft"</SPAN><SPAN class="punctuation token">)</SPAN>
sd <SPAN class="operator token">=</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN>relPath<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"CurrentUpdate.sd"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Create a new SDDraft and stage to SD</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Creating SD file"</SPAN><SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>overwriteOutput <SPAN class="operator token">=</SPAN> <SPAN class="token boolean">True</SPAN>
prj <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>mp<SPAN class="punctuation token">.</SPAN>ArcGISProject<SPAN class="punctuation token">(</SPAN>prjPath<SPAN class="punctuation token">)</SPAN>
mp <SPAN class="operator token">=</SPAN> prj<SPAN class="punctuation token">.</SPAN>listMaps<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>mp<SPAN class="punctuation token">.</SPAN>CreateWebLayerSDDraft<SPAN class="punctuation token">(</SPAN>mp<SPAN class="punctuation token">,</SPAN> sddraft<SPAN class="punctuation token">,</SPAN> sd_fs_name<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'MY_HOSTED_SERVICES'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'FEATURE_ACCESS'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="token boolean">True</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="token boolean">True</SPAN><SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>StageService_server<SPAN class="punctuation token">(</SPAN>sddraft<SPAN class="punctuation token">,</SPAN> sd<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Connecting to {}"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>portal<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
gis <SPAN class="operator token">=</SPAN> GIS<SPAN class="punctuation token">(</SPAN>portal<SPAN class="punctuation token">,</SPAN> user<SPAN class="punctuation token">,</SPAN> password<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Find the SD, update it, publish /w overwrite and set sharing and metadata</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Search for original SD on portal…"</SPAN><SPAN class="punctuation token">)</SPAN>
sdItem <SPAN class="operator token">=</SPAN> gis<SPAN class="punctuation token">.</SPAN>content<SPAN class="punctuation token">.</SPAN>search<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"{} AND owner:{}"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>sd_fs_name<SPAN class="punctuation token">,</SPAN> user<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> item_type<SPAN class="operator token">=</SPAN><SPAN class="string token">"Service Definition"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Found SD: {}, ID: {} n Uploading and overwriting…"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>sdItem<SPAN class="punctuation token">.</SPAN>title<SPAN class="punctuation token">,</SPAN> sdItem<SPAN class="punctuation token">.</SPAN>id<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
sdItem<SPAN class="punctuation token">.</SPAN>update<SPAN class="punctuation token">(</SPAN>data<SPAN class="operator token">=</SPAN>sd<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Overwriting existing feature service…"</SPAN><SPAN class="punctuation token">)</SPAN>
fs <SPAN class="operator token">=</SPAN> sdItem<SPAN class="punctuation token">.</SPAN>publish<SPAN class="punctuation token">(</SPAN>overwrite<SPAN class="operator token">=</SPAN><SPAN class="token boolean">True</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">if</SPAN> shrOrg <SPAN class="operator token">or</SPAN> shrEveryone <SPAN class="operator token">or</SPAN> shrGroups<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Setting sharing options…"</SPAN><SPAN class="punctuation token">)</SPAN>
fs<SPAN class="punctuation token">.</SPAN>share<SPAN class="punctuation token">(</SPAN>org<SPAN class="operator token">=</SPAN>shrOrg<SPAN class="punctuation token">,</SPAN> everyone<SPAN class="operator token">=</SPAN>shrEveryone<SPAN class="punctuation token">,</SPAN> groups<SPAN class="operator token">=</SPAN>shrGroups<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Finished updating: {} – ID: {}"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>fs<SPAN class="punctuation token">.</SPAN>title<SPAN class="punctuation token">,</SPAN> fs<SPAN class="punctuation token">.</SPAN>id<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>Once again, specific filenames have been X'd out with number of characters and any spacing preserved. This script successfully updates the map as intended when logged in to ArcGIS Pro.