API for Python script publishing as GP service

717
1
Jump to solution
12-12-2022 09:50 PM
sirishb
New Contributor III

Hi All,

ArcGIS enterprise version: 10.9.1 & ArcGIS Pro 2.9 & Python version 3.7.11

Versioning type: Branch Version

We have published "Feature" services with "Version Management" capability.

Requirement:

1) Field Users perform edits on "Feature Service"

2) Using ArcGIS Workflow manager automate the "Reconcile & Post" activity using GP Service

Implemented Steps:

1) We have developed a python script (API for Python) and created a toolbox.

2) When we execute the same in ArcGIS Pro, it is working fine.

3) While trying to publish as GP Service using "Share Web Tool", getting the following errors

sirishb_0-1670909592653.png

4) Getting the same error for the both options 

sirishb_1-1670909970436.png

sirishb_2-1670910116421.png

 

 

Python Script:

# Tool:        Branch Version Reconcile & Post using the ArcGIS Python API
##-----------------------------------------------------------------------------------------------
##----------------- Modules -------------------------------------------------------------
# import modules
import arcpy, datetime, requests, os
import arcgis.features
from arcgis.gis import GIS
#import Config
import time
import urllib.parse
# Disable warnings
requests.packages.urllib3.disable_warnings()
##----------------------------- Input & Derived Parameters ----------------------------------------
arcpy.env.overwriteOutput = True;

ftr_service =arcpy.GetParameterAsText(0)
vms_service = arcpy.GetParameterAsText(1)
version_name =arcpy.GetParameterAsText(2)
out_code = arcpy.GetParameterAsText(3)

# ftr_service = "https://<WEBADAPTOR NAME>/arcgis/rest/services/testFeatureService/FeatureServer"
# vms_service = "https://<WEBADAPTOR NAME>/arcgis/rest/services/testFeatureService/VersionManagementServer"
# version_name = "admin.testVersion"
# out_code = 0

print("Start GP Tool")
arcpy.AddMessage("Start GP Tool")
base_url = ftr_service
#--------------------------------------------------------------------------------------------------
try:
    start_time = datetime.datetime.now()
    # Service URLs and GIS object
    portalURL = "https://<WEBADAPTOR NAME>/portal/home/index.html"
    portal = GIS(url = portalURL, username = 'username', password = 'password', verify_cert = False)
    
    # Create a VersionManagementServer of service url
    version_mgmt_svc = vms_service
    vms = arcgis.features._version.VersionManager(version_mgmt_svc, portal)
    print(portal)
    arcpy.AddMessage(f'Version Management Service: {vms}')
    
    # Check if the new version exists and get the fully qualified version name from the version's properties ('owner.versionName')
    _version = [x for x in vms.all if version_name in x.properties.versionName]
    fq_version_name = _version[0].properties.versionName
    print(_version[0].properties)
    arcpy.AddMessage(f'Version properties: {_version[0].properties}')   
    
    # Reconcile the version with Default
    with vms.get(version_name, mode="edit") as version:
        print("Start reconcile...")
        try:
            arcpy.AddMessage(f"Reconciling...")
            print(f"Reconciling...")
            reconcile_res = version.reconcile(end_with_conflict=True, with_post=True)
            arcpy.AddMessage(f"Results of Reconcile & Post: {reconcile_res}")
            print(f"Results of Reconcile & Post: {reconcile_res}")

            if not reconcile_res:
                arcpy.AddMessage(f"Reconciling the version {version.properties.versionName} failed.")
                out_code = 0
                raise Exception(f"Reconciling the version {version.properties.versionName} failed.")

            arcpy.AddMessage(f"Reconciled and posted version: {version.properties.versionName}")
            arcpy.AddMessage(f"Output Code: {reconcile_res}")
            out_code = 1

            arcpy.SetParameter(3, out_code)
            arcpy.AddMessage(out_code)

            end_time = datetime.datetime.now()
            elapsed_time = end_time - start_time
            arcpy.AddMessage(f"Dataset was locked for {elapsed_time.total_seconds()} secs")
            
        except Exception as ex:
            arcpy.AddMessage(f'Exception 2: {str(ex)}')
            print(f'Exception 2: {str(ex)}')
            out_code = 0
            arcpy.AddMessage(out_code)
            arcpy.SetParameter(3, out_code)
except Exception as ex:
    arcpy.AddMessage(f'Exception 1: {str(ex)}')
    print(f'Exception 1: {str(ex)}')
    out_code = 0    
    arcpy.AddMessage(out_code)
    arcpy.SetParameter(3, out_code)

 

Any suggestions please.

Regards,

Sirish

 

 

0 Kudos
1 Solution

Accepted Solutions
1 Reply
Ranga_Tolapi
Occasional Contributor III