ArcGIS API for Python <urlopen error [WinError 10054] An existing connection was forcibly closed by the remote host> when adding Vector Tile Package to Portal

03-05-2018 02:58 PM
Occasional Contributor III

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')
    # Query Project for CPAreasVector Map
    p =
    lyt = p.listMaps(mapQuery)[0]"Creating Vector Tiles for " +
    #, outputPath + + '.vtpk', tileScheme, "", indexScheme, "", "",
                                             # indexShp)"Vector Tile Creation Complete for " +
    # Find VTPK File that has been uploaded
    vtpkFile =, item_type=vtPackage)
    if len(vtpkFile) > 0:
        first_item = vtpkFile[0]
        if first_item.title == mapTitle:
            known_item_id =
            vtpkFileDelete = gis.content.get(known_item_id)
  "Deleting Old VTPK Layer From Test Portal")
    else:"There is no VTPK File Found")
    # Add VTPK to Portal"Adding VTPK to Test Portal")
    vtpk_item = gis.content.add({}, data=outputPath + + '.vtpk', folder='packages')
    # Delete old Service
    vtpkLayer ="CPAreasVector", item_type="Vector Tile Service")"Number of service items")
    if len(vtpkLayer) > 0:
       vLayerID = vtpkLayer[0]
       if vLayerID.title == mapTitle:
          vLayer_item_id =

          vtpkLayerDelete = gis.content.get(vLayer_item_id)
"Deleting Old VTPK Service From Test Portal")
    else:"There is no VTPK Layer Found")
    # Publish VTPK"Publishing & Overwriting VTPK to Test Portal")
    vtpk_hLayer = vtpk_item.publish()
    # Share to Group"Sharing to CP Group in Test Portal")
    cp_group ='title:SCG - Cathodic Protection', max_groups=15)
    cpgroup_share = cp_group[0]
except Exception as e :

1 Reply
MVP Honored Contributor


Were you ever able to figure this out?

0 Kudos