Select to view content in your preferred language

Script fails to create Vector Tile Package based on Portal environment

110
2
Thursday
Brian_McLeer
Occasional Contributor II

I am working on a script that will create a Vector Tile Package from ArcGIS Pro and publish to Portal. In my testing portal environment, it functions as expected. When I switch the Portal URL, ItemIDs, etc to my production Portal, I get the below error. 

ERROR - Error updating item PortalItemID: ('Failed to create Vector Tile Package MapName: Item with this filename already exists. [itemId=PortalItemID]\n(Error Code: 409)', None)

Does anyone have any suggestions on what might cause this behavior to exist in one instance of Portal but not another? The environment is ArcGIS Enterprise 11.2. 

Brian
0 Kudos
2 Replies
HaydenWelch
Occasional Contributor II

Does arcpy.Exists return true when you run out on the output item path? It seems like you either already have an item with that name on your production server or you are creating it twice in your script. Given that your development server test worked I think it's probably the former.

You could test this by running an Exists check and just appending a '_new' to the file name. That way it will say least complete and show you something.

0 Kudos
TonyAlmeida
Occasional Contributor III

Maybe some debugging and handle the 409 error when publishing a Vector Tile Package

untested.

import arcgis
from arcgis.gis import GIS
from arcgis.gis import Item
import os

# Connect to your GIS
portal_url = "https://yourproductionportalurl.com/portal"
username = "yourusername"
password = "yourpassword"
gis = GIS(portal_url, username, password)

# Define variables
vector_tile_package_path = "path_to_your_vector_tile_package.vtpk"
item_title = "Your Vector Tile Package Title"
item_description = "Description of your vector tile package"
tags = "tag1, tag2, tag3"

# Check if an item with the same title already exists
def check_existing_items(title):
    existing_items = gis.content.search(query=title, item_type="Vector Tile Package")
    for item in existing_items:
        if item.title == title:
            return item
    return None

# Function to publish the vector tile package
def publish_vector_tile_package():
    try:
        # Check for existing items with the same title
        existing_item = check_existing_items(item_title)
        if existing_item:
            print(f"Item with the title '{item_title}' already exists. Deleting the existing item.")
            existing_item.delete()

        # Upload and publish the vector tile package
        print("Uploading the vector tile package...")
        item_properties = {
            "title": item_title,
            "type": "Vector Tile Package",
            "description": item_description,
            "tags": tags
        }
        item = gis.content.add(item_properties, data=vector_tile_package_path)
        print(f"Publishing the vector tile package '{item_title}'...")
        item.publish()

        print("Vector Tile Package published successfully.")
    except arcgis.exceptions.ArcGISException as e:
        if "409" in str(e):
            print(f"Error 409: Conflict. {e}")
        else:
            print(f"An error occurred: {e}")

# Run the function to publish the vector tile package
publish_vector_tile_package()