Select to view content in your preferred language

Publishing ArcGIS API python script as a geoprocessing tool

07-27-2017 03:26 PM
New Contributor III

I'm trying to publish a geoprocessing tool from Pro using a python script and the ArcGIS API for Python.  The script is very simple and works well from Pro, but it will not publish to either of my Server sites, one which is hosted.  Is it not possible to publish using this new API to Server?  Can it only be used from the local workstation python interface and/or Pro?

Here is my script:

from arcgis.gis import GIS
import shutil, os, arcpy

newPolyName = arcpy.GetParameterAsText(0)          # Layer name
featureType = arcpy.GetParameterAsText(1)          # Feature type:  Point, Line or Polygon
userName = arcpy.GetParameterAsText(2)             # User login
pword = arcpy.GetParameterAsText(3)                # User password

gis = GIS(r"", userName, pword)

newShapeFileName = r"\\gis-bj\E\Data\AutoPublishUTMLayer\OutputShapefile" + chr(92) + newPolyName + ".shp"
print(r'copy \\gis-bj\E\Data\AutoPublishUTMLayer\Empty' + featureType + r'UTM.* \\gis-bj\E\Data\AutoPublishUTMLayer\OutputShapefile' + chr(92) + newPolyName + '.*')
os.system(r'copy \\gis-bj\E\Data\AutoPublishUTMLayer\Empty' + featureType + r'UTM.* \\gis-bj\E\Data\AutoPublishUTMLayer\OutputShapefile' + chr(92) + newPolyName + '.*')
shutil.make_archive(r"\\gis-bj\E\Data\AutoPublishUTMLayer" + chr(92) + newPolyName, 'zip', r"\\gis-bj\E\Data\AutoPublishUTMLayer\OutputShapefile")

data = r"\\gis-bj\E\Data\AutoPublishUTMLayer" + chr(92) + newPolyName  + ".zip"
shpfile = gis.content.add({}, data)
published_service = shpfile.publish({"name": newPolyName,"targetSR":{"wkid":26911}})

os.system(r'del /q \\gis-bj\E\Data\AutoPublishUTMLayer\OutputShapefile\*.*')
os.system(r'del /q \\gis-bj\E\Data\AutoPublishUTMLayer\*.zip')
0 Kudos
3 Replies
Esri Contributor

Server does not contain the ArcGIS API for Python library and that would explain why it's failing.

New Contributor III

Is this something that is going to be implemented in Server Enterprise?  It's something I could really use right now.  It's been literally several years now I've been waiting for the capabilities that the ArcGIS API for Python has.

by Anonymous User
Not applicable

I would second this - would love to know if/when ArcGIS Server will support the ArcGIS API. I would love to take advantage of the layout and symbology control that the API brings but in a GP service.

Anyone able to provide some info on whether this is on the roadmap for ESRI?