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.
from arcgis.gis import GIS
import os
import arcpy
import logging
# set environment settings
gis = GIS("myDetails")
arcpy.env.workspace = r"E:\GIS_PROJECTS\VTPK"
arcpy.env.overwriteOutput = True
start = time.time()
outputPath = r"E:\GIS_PROJECTS\VTPK\\"
tileScheme = "ONLINE"
indexScheme = "INDEXED"
vtpkTitle = "title:CPAreasVector"
mapTitle = "CPAreasVector"
vtPackage = "Vector Tile Package"
mapQuery = "CPAreasVector*"
vts = "Vector Tile Service"
indexShp = r'E:\GIS_PROJECTS\VTPK\INDEX\CPAreas\CPAreas.shp'
project = r"E:\GIS_PROJECTS\VTPK\CPVektrTile.aprx"
arcpy.env.parallelProcessingFactor = "66%"
logging.basicConfig(filename=r"E:\GIS_PROJECTS\VTPK\log.log", level=logging.INFO,
format='%(asctime)s %(message)s')
try:
# Query Project for CPAreasVector Map
p = arcpy.mp.ArcGISProject(project)
lyt = p.listMaps(mapQuery)[0]
logging.info("Creating Vector Tiles for " + lyt.name)
# arcpy.management.CreateVectorTilePackage(lyt, outputPath + lyt.name + '.vtpk', tileScheme, "", indexScheme, "", "",
# indexShp)
logging.info("Vector Tile Creation Complete for " + lyt.name)
# Find VTPK File that has been uploaded
vtpkFile = gis.content.search(query=vtpkTitle, item_type=vtPackage)
logging.info(len(vtpkFile))
if len(vtpkFile) > 0:
first_item = vtpkFile[0]
logging.info(first_item)
if first_item.title == mapTitle:
known_item_id = first_item.id
logging.info(known_item_id)
vtpkFileDelete = gis.content.get(known_item_id)
logging.info("Deleting Old VTPK Layer From Test Portal")
vtpkFileDelete.delete()
else:
logging.info("There is no VTPK File Found")
# Add VTPK to Portal
logging.info("Adding VTPK to Test Portal")
vtpk_item = gis.content.add({}, data=outputPath + lyt.name + '.vtpk', folder='packages')
# Delete old Service
vtpkLayer = gis.content.search(query="CPAreasVector", item_type="Vector Tile Service")
logging.info("Number of service items")
logging.info(len(vtpkFile))
if len(vtpkLayer) > 0:
vLayerID = vtpkLayer[0]
if vLayerID.title == mapTitle:
vLayer_item_id = vLayerID.id
logging.info(vLayer_item_id)
vtpkLayerDelete = gis.content.get(vLayer_item_id)
logging.info("Deleting Old VTPK Service From Test Portal")
vtpkLayerDelete.delete()
else:
logging.info("There is no VTPK Layer Found")
# Publish VTPK
logging.info("Publishing & Overwriting VTPK to Test Portal")
vtpk_hLayer = vtpk_item.publish()
# Share to Group
logging.info("Sharing to CP Group in Test Portal")
cp_group = gis.groups.search('title:SCG - Cathodic Protection', max_groups=15)
cpgroup_share = cp_group[0]
vtpk_hLayer.share(groups=cpgroup_share.id)
logging.info("Complete")
except Exception as e :
logging.info(e)
Geoffrey,
Were you ever able to figure this out?