I have been receiving this error when accessing my organization's portal It is intermittent, what could be the cause of it. Typically I am seeing this error occur at line 53. The VTPK is not able to be added to my Portal. The error is not consistent as it appears sometimes, and other times it does not.
<SPAN class="keyword token">from</SPAN> arcgis<SPAN class="punctuation token">.</SPAN>gis <SPAN class="keyword token">import</SPAN> GIS
<SPAN class="keyword token">import</SPAN> os
<SPAN class="keyword token">import</SPAN> arcpy
<SPAN class="keyword token">import</SPAN> logging
<SPAN class="comment token"># set environment settings</SPAN>
gis <SPAN class="operator token">=</SPAN> GIS<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"myDetails"</SPAN><SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>workspace <SPAN class="operator token">=</SPAN> r<SPAN class="string token">"E:\GIS_PROJECTS\VTPK"</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>
start <SPAN class="operator token">=</SPAN> time<SPAN class="punctuation token">.</SPAN>time<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
outputPath <SPAN class="operator token">=</SPAN> r<SPAN class="string token">"E:\GIS_PROJECTS\VTPK\\"</SPAN>
tileScheme <SPAN class="operator token">=</SPAN> <SPAN class="string token">"ONLINE"</SPAN>
indexScheme <SPAN class="operator token">=</SPAN> <SPAN class="string token">"INDEXED"</SPAN>
vtpkTitle <SPAN class="operator token">=</SPAN> <SPAN class="string token">"title:CPAreasVector"</SPAN>
mapTitle <SPAN class="operator token">=</SPAN> <SPAN class="string token">"CPAreasVector"</SPAN>
vtPackage <SPAN class="operator token">=</SPAN> <SPAN class="string token">"Vector Tile Package"</SPAN>
mapQuery <SPAN class="operator token">=</SPAN> <SPAN class="string token">"CPAreasVector*"</SPAN>
vts <SPAN class="operator token">=</SPAN> <SPAN class="string token">"Vector Tile Service"</SPAN>
indexShp <SPAN class="operator token">=</SPAN> r<SPAN class="string token">'E:\GIS_PROJECTS\VTPK\INDEX\CPAreas\CPAreas.shp'</SPAN>
project <SPAN class="operator token">=</SPAN> r<SPAN class="string token">"E:\GIS_PROJECTS\VTPK\CPVektrTile.aprx"</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>parallelProcessingFactor <SPAN class="operator token">=</SPAN> <SPAN class="string token">"66%"</SPAN>
logging<SPAN class="punctuation token">.</SPAN>basicConfig<SPAN class="punctuation token">(</SPAN>filename<SPAN class="operator token">=</SPAN>r<SPAN class="string token">"E:\GIS_PROJECTS\VTPK\log.log"</SPAN><SPAN class="punctuation token">,</SPAN> level<SPAN class="operator token">=</SPAN>logging<SPAN class="punctuation token">.</SPAN>INFO<SPAN class="punctuation token">,</SPAN>
format<SPAN class="operator token">=</SPAN><SPAN class="string token">'%(asctime)s %(message)s'</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">try</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="comment token"># Query Project for CPAreasVector Map</SPAN>
p <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>mp<SPAN class="punctuation token">.</SPAN>ArcGISProject<SPAN class="punctuation token">(</SPAN>project<SPAN class="punctuation token">)</SPAN>
lyt <SPAN class="operator token">=</SPAN> p<SPAN class="punctuation token">.</SPAN>listMaps<SPAN class="punctuation token">(</SPAN>mapQuery<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN>
logging<SPAN class="punctuation token">.</SPAN>info<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Creating Vector Tiles for "</SPAN> <SPAN class="operator token">+</SPAN> lyt<SPAN class="punctuation token">.</SPAN>name<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># arcpy.management.CreateVectorTilePackage(lyt, outputPath + lyt.name + '.vtpk', tileScheme, "", indexScheme, "", "",</SPAN>
<SPAN class="comment token"># indexShp)</SPAN>
logging<SPAN class="punctuation token">.</SPAN>info<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Vector Tile Creation Complete for "</SPAN> <SPAN class="operator token">+</SPAN> lyt<SPAN class="punctuation token">.</SPAN>name<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Find VTPK File that has been uploaded</SPAN>
vtpkFile <SPAN class="operator token">=</SPAN> gis<SPAN class="punctuation token">.</SPAN>content<SPAN class="punctuation token">.</SPAN>search<SPAN class="punctuation token">(</SPAN>query<SPAN class="operator token">=</SPAN>vtpkTitle<SPAN class="punctuation token">,</SPAN> item_type<SPAN class="operator token">=</SPAN>vtPackage<SPAN class="punctuation token">)</SPAN>
logging<SPAN class="punctuation token">.</SPAN>info<SPAN class="punctuation token">(</SPAN>len<SPAN class="punctuation token">(</SPAN>vtpkFile<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">if</SPAN> len<SPAN class="punctuation token">(</SPAN>vtpkFile<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">></SPAN> <SPAN class="number token">0</SPAN><SPAN class="punctuation token">:</SPAN>
first_item <SPAN class="operator token">=</SPAN> vtpkFile<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN>
logging<SPAN class="punctuation token">.</SPAN>info<SPAN class="punctuation token">(</SPAN>first_item<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">if</SPAN> first_item<SPAN class="punctuation token">.</SPAN>title <SPAN class="operator token">==</SPAN> mapTitle<SPAN class="punctuation token">:</SPAN>
known_item_id <SPAN class="operator token">=</SPAN> first_item<SPAN class="punctuation token">.</SPAN>id
logging<SPAN class="punctuation token">.</SPAN>info<SPAN class="punctuation token">(</SPAN>known_item_id<SPAN class="punctuation token">)</SPAN>
vtpkFileDelete <SPAN class="operator token">=</SPAN> gis<SPAN class="punctuation token">.</SPAN>content<SPAN class="punctuation token">.</SPAN>get<SPAN class="punctuation token">(</SPAN>known_item_id<SPAN class="punctuation token">)</SPAN>
logging<SPAN class="punctuation token">.</SPAN>info<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Deleting Old VTPK Layer From Test Portal"</SPAN><SPAN class="punctuation token">)</SPAN>
vtpkFileDelete<SPAN class="punctuation token">.</SPAN>delete<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">else</SPAN><SPAN class="punctuation token">:</SPAN>
logging<SPAN class="punctuation token">.</SPAN>info<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"There is no VTPK File Found"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Add VTPK to Portal</SPAN>
logging<SPAN class="punctuation token">.</SPAN>info<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Adding VTPK to Test Portal"</SPAN><SPAN class="punctuation token">)</SPAN>
vtpk_item <SPAN class="operator token">=</SPAN> gis<SPAN class="punctuation token">.</SPAN>content<SPAN class="punctuation token">.</SPAN>add<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">{</SPAN><SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">,</SPAN> data<SPAN class="operator token">=</SPAN>outputPath <SPAN class="operator token">+</SPAN> lyt<SPAN class="punctuation token">.</SPAN>name <SPAN class="operator token">+</SPAN> <SPAN class="string token">'.vtpk'</SPAN><SPAN class="punctuation token">,</SPAN> folder<SPAN class="operator token">=</SPAN><SPAN class="string token">'packages'</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Delete old Service</SPAN>
vtpkLayer <SPAN class="operator token">=</SPAN> gis<SPAN class="punctuation token">.</SPAN>content<SPAN class="punctuation token">.</SPAN>search<SPAN class="punctuation token">(</SPAN>query<SPAN class="operator token">=</SPAN><SPAN class="string token">"CPAreasVector"</SPAN><SPAN class="punctuation token">,</SPAN> item_type<SPAN class="operator token">=</SPAN><SPAN class="string token">"Vector Tile Service"</SPAN><SPAN class="punctuation token">)</SPAN>
logging<SPAN class="punctuation token">.</SPAN>info<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Number of service items"</SPAN><SPAN class="punctuation token">)</SPAN>
logging<SPAN class="punctuation token">.</SPAN>info<SPAN class="punctuation token">(</SPAN>len<SPAN class="punctuation token">(</SPAN>vtpkFile<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">if</SPAN> len<SPAN class="punctuation token">(</SPAN>vtpkLayer<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">></SPAN> <SPAN class="number token">0</SPAN><SPAN class="punctuation token">:</SPAN>
vLayerID <SPAN class="operator token">=</SPAN> vtpkLayer<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="keyword token">if</SPAN> vLayerID<SPAN class="punctuation token">.</SPAN>title <SPAN class="operator token">==</SPAN> mapTitle<SPAN class="punctuation token">:</SPAN>
vLayer_item_id <SPAN class="operator token">=</SPAN> vLayerID<SPAN class="punctuation token">.</SPAN>id
logging<SPAN class="punctuation token">.</SPAN>info<SPAN class="punctuation token">(</SPAN>vLayer_item_id<SPAN class="punctuation token">)</SPAN>
vtpkLayerDelete <SPAN class="operator token">=</SPAN> gis<SPAN class="punctuation token">.</SPAN>content<SPAN class="punctuation token">.</SPAN>get<SPAN class="punctuation token">(</SPAN>vLayer_item_id<SPAN class="punctuation token">)</SPAN>
logging<SPAN class="punctuation token">.</SPAN>info<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Deleting Old VTPK Service From Test Portal"</SPAN><SPAN class="punctuation token">)</SPAN>
vtpkLayerDelete<SPAN class="punctuation token">.</SPAN>delete<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">else</SPAN><SPAN class="punctuation token">:</SPAN>
logging<SPAN class="punctuation token">.</SPAN>info<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"There is no VTPK Layer Found"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Publish VTPK</SPAN>
logging<SPAN class="punctuation token">.</SPAN>info<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Publishing & Overwriting VTPK to Test Portal"</SPAN><SPAN class="punctuation token">)</SPAN>
vtpk_hLayer <SPAN class="operator token">=</SPAN> vtpk_item<SPAN class="punctuation token">.</SPAN>publish<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Share to Group</SPAN>
logging<SPAN class="punctuation token">.</SPAN>info<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Sharing to CP Group in Test Portal"</SPAN><SPAN class="punctuation token">)</SPAN>
cp_group <SPAN class="operator token">=</SPAN> gis<SPAN class="punctuation token">.</SPAN>groups<SPAN class="punctuation token">.</SPAN>search<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'title:SCG - Cathodic Protection'</SPAN><SPAN class="punctuation token">,</SPAN> max_groups<SPAN class="operator token">=</SPAN><SPAN class="number token">15</SPAN><SPAN class="punctuation token">)</SPAN>
cpgroup_share <SPAN class="operator token">=</SPAN> cp_group<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN>
vtpk_hLayer<SPAN class="punctuation token">.</SPAN>share<SPAN class="punctuation token">(</SPAN>groups<SPAN class="operator token">=</SPAN>cpgroup_share<SPAN class="punctuation token">.</SPAN>id<SPAN class="punctuation token">)</SPAN>
logging<SPAN class="punctuation token">.</SPAN>info<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Complete"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">except</SPAN> Exception <SPAN class="keyword token">as</SPAN> e <SPAN class="punctuation token">:</SPAN>
logging<SPAN class="punctuation token">.</SPAN>info<SPAN class="punctuation token">(</SPAN>e<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></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>