<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: API for Python script publishing as GP service in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/api-for-python-script-publishing-as-gp-service/m-p/1242634#M8187</link>
    <description>&lt;P&gt;Hello,&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/423103"&gt;@sirishb&lt;/a&gt;&amp;nbsp;please follow&amp;nbsp;&lt;A href="https://support.esri.com/en/technical-article/000022882" target="_blank" rel="noopener nofollow noreferrer"&gt;https://support.esri.com/en/technical-article/000022882&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 20 Dec 2022 11:32:44 GMT</pubDate>
    <dc:creator>Ranga_Tolapi</dc:creator>
    <dc:date>2022-12-20T11:32:44Z</dc:date>
    <item>
      <title>API for Python script publishing as GP service</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/api-for-python-script-publishing-as-gp-service/m-p/1240474#M8152</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;ArcGIS enterprise version: 10.9.1 &amp;amp; ArcGIS Pro 2.9 &amp;amp; Python version 3.7.11&lt;/P&gt;&lt;P&gt;Versioning type: Branch Version&lt;/P&gt;&lt;P&gt;We have published "Feature" services with "Version Management" capability.&lt;/P&gt;&lt;P&gt;Requirement:&lt;/P&gt;&lt;P&gt;1) Field Users perform edits on "Feature Service"&lt;/P&gt;&lt;P&gt;2) Using ArcGIS Workflow manager automate the "Reconcile &amp;amp; Post" activity using GP Service&lt;/P&gt;&lt;P&gt;Implemented Steps:&lt;/P&gt;&lt;P&gt;1) We have developed a python script (API for Python) and created a toolbox.&lt;/P&gt;&lt;P&gt;2) When we execute the same in ArcGIS Pro, it is working fine.&lt;/P&gt;&lt;P&gt;3) While trying to publish as&amp;nbsp;GP Service using "Share Web Tool", getting the following errors&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sirishb_0-1670909592653.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/58347i38A33FE41F4680D9/image-size/medium?v=v2&amp;amp;px=400" role="button" title="sirishb_0-1670909592653.png" alt="sirishb_0-1670909592653.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;4) Getting the same error for the both options&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sirishb_1-1670909970436.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/58348i83C32A0C945EB05C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="sirishb_1-1670909970436.png" alt="sirishb_1-1670909970436.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sirishb_2-1670910116421.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/58349i467F021E0B91D1CE/image-size/medium?v=v2&amp;amp;px=400" role="button" title="sirishb_2-1670910116421.png" alt="sirishb_2-1670910116421.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Python Script:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# Tool:        Branch Version Reconcile &amp;amp; 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 &amp;amp; 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://&amp;lt;WEBADAPTOR NAME&amp;gt;/arcgis/rest/services/testFeatureService/FeatureServer"
# vms_service = "https://&amp;lt;WEBADAPTOR NAME&amp;gt;/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://&amp;lt;WEBADAPTOR NAME&amp;gt;/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 &amp;amp; Post: {reconcile_res}")
            print(f"Results of Reconcile &amp;amp; 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)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any suggestions please.&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Sirish&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Dec 2022 05:50:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/api-for-python-script-publishing-as-gp-service/m-p/1240474#M8152</guid>
      <dc:creator>sirishb</dc:creator>
      <dc:date>2022-12-13T05:50:28Z</dc:date>
    </item>
    <item>
      <title>Re: API for Python script publishing as GP service</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/api-for-python-script-publishing-as-gp-service/m-p/1242634#M8187</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/423103"&gt;@sirishb&lt;/a&gt;&amp;nbsp;please follow&amp;nbsp;&lt;A href="https://support.esri.com/en/technical-article/000022882" target="_blank" rel="noopener nofollow noreferrer"&gt;https://support.esri.com/en/technical-article/000022882&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Dec 2022 11:32:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/api-for-python-script-publishing-as-gp-service/m-p/1242634#M8187</guid>
      <dc:creator>Ranga_Tolapi</dc:creator>
      <dc:date>2022-12-20T11:32:44Z</dc:date>
    </item>
  </channel>
</rss>

