Python over CGI on IIS

895
5
06-12-2017 07:20 AM
irishadar
New Contributor III

hi,

I have configure python to work over CGI on iis,

I got the script to work, but on top of it working relay slow , I keep getting some extra information when executing arcpy functions.

for example:

arcpy.FeatureClassToGeodatabase_conversion(Input_Features, msurvey_rashutnew_sde)

returns 

\\serverName\SurveyData\Survey_Template_3.gdb\PNT_TMP_3 Successfully converted: \\serverName\PythonApp\msurvey@rashutnew.sde\PNT_TMP_3

so my script returns "invalid haderes".

is there another way to run python with arcpay on web page ?

thanks

iris

0 Kudos
5 Replies
JonathanQuinn
Esri Frequent Contributor

I don't have any input on your workflow, but have you looked into a GP service?  If you have ArcGIS Server you could create your own GP service so you can run geoprocessing tasks through the web.

0 Kudos
irishadar
New Contributor III

Jonathan Quinn Hi,

thank you for your response.

We are familiar with GP services and use quit a lot for many purposes, but I don’t think It will work for this workflow, I would be happy to know what you think.

Our workflow needs to automate creating new WebMap to be used in a Collector, with new uniquely named editable layer coming from SDE, based on FGDB templated. 

This is our workflow steps, each represents working python script. For all them to work together I wanted to use html page which will invoke each of them separately:

      1. Copy empty FGDB containing domains and subtype to Oracle SDE.

Create global Id, attachments and archiving on the new layer using arcpy.

2. Create feature service from that layer on ArcGis Server using arcpy.

 

3. Since there is no other why to add feature access to service, this step is adding it through modifying Json of the service using "rest api ".

 

4. Creating item in " ArcGIs online" from that service and WebMap using that item , all to be used  in ArcGIs collector. this part is using new python api.

So… we were almost there except that massage from python announcing its success, which I really don’t know where it is coming from.

\serverName\SurveyData\Survey_Template_3.gdb\PNT_TMP_3 Successfully converted: \\serverName\PythonApp\msurvey@rashutnew.sde\PNT_TMP_3

Best regrades,

iris

0 Kudos
JonathanQuinn
Esri Frequent Contributor

Can you clarify the following two points?

2. Create feature service from that layer on ArcGis Server using arcpy.

 

3. Since there is no other why to add feature access to service, this step is adding it through modifying Json of the service using "rest api ".

Using the CreateMapSDDraft tool, you're able to modify the sddraft to enable the feature access capability.  When you stage the SD file and then upload it, the resulting service will have feature access enabled.

In regards to running them through an HTML page, is that so you can start the process from anywhere?

0 Kudos
irishadar
New Contributor III

Hi Jonathan,

I’ve used two steps for getting a “feature service” because I couldn’t modify the “SDDraft” to add “feature Access” to it.

I followed the “Modify SDDraft example 4” and try to enable “FeatureServer”, it didn’t work , so I went ahead and modified it through rest.

In regards to the use of one html page, it is needed since this workflow is part of a big “Javascript api” application.

This is the script I  used.

import arcpy, os, sys
import xml.dom.minidom as DOM
wrkspc = "c:\\SurveyData\\"
mxd = arcpy.mapping.MapDocument(r"C:\SurveyData\temp.mxd")
mxd.saveACopy(r"c:\SurveyData\testing1.mxd")
print mxd.filePath
inFC = "Database Connections\\msurvey@rashutnew.sde\\MSURVEY.PNT_TMP_1"
arcpy.MakeFeatureLayer_management(inFC, "TestData")
mxd = arcpy.mapping.MapDocument(r"c:\SurveyData\testing.mxd")
df = arcpy.mapping.ListDataFrames(mxd)[0]
lyrLayer =arcpy.mapping.Layer("TestData")
arcpy.mapping.AddLayer(df, lyrLayer, "AUTO_ARRANGE")
##mxd.save()
mxd.saveACopy(r"c:\SurveyData\topublish1.mxd")
del mxd

con = "Database Connections\\arcgis on gis-develop (admin)"
mapDoc=r"c:\SurveyData\topublish1.mxd"
### Provide other service details
service = 'TestSurIris3'
sddraft = wrkspc + service + '.sddraft'
sd = wrkspc + service + '.sd'

print sd
summary = 'General reference map Test ssdraft'
tags = 'TEST'

# Create service definition draft
arcpy.mapping.CreateMapSDDraft(mapDoc, sddraft, service, 'ARCGIS_SERVER', con, False, None, summary, tags)
# The Server Object Extension (SOE) to enable.
soe = 'FeatureServer'
# Read the sddraft xml.
doc = DOM.parse(sddraft)
# Find all elements named TypeName. This is where the server object extension (SOE) names are defined.
typeNames = doc.getElementsByTagName('TypeName')
for typeName in typeNames:
 # Get the TypeName we want to disable.
 if typeName.firstChild.data == soe:
 extension = typeName.parentNode
 for extElement in extension.childNodes:
 # Disabled SOE.
 if extElement.tagName == 'Disabled':
 extElement.firstChild.data = 'true'
# Output to a new sddraft.
outXml = wrkspc +'TestSurIris3ForWeb.sddraft'
sd=wrkspc+'TestSurIris3ForWeb.sd'
f = open(outXml, 'w')
doc.writexml( f )
f.close()

# Analyze the service definition draft
analysis = arcpy.mapping.AnalyzeForSD(outXml)
# Print errors, warnings, and messages returned from the analysis
print "The following information was returned during analysis of the MXD:"
for key in ('messages', 'warnings', 'errors'):
 print '----' + key.upper() + '---'
 vars = analysis[key]
 for ((message, code), layerlist) in vars.iteritems():
 print ' ', message, ' (CODE %i)' % code
 print ' applies to:',
 for layer in layerlist:
 print layer.name,
 print
# Stage and upload the service if the sddraft analysis did not contain errors
if analysis['errors'] == {}:
 # Execute StageService. This creates the service definition.
 arcpy.StageService_server(outXml, sd)
# Execute UploadServiceDefinition. This uploads the service definition and publishes the service.
 arcpy.UploadServiceDefinition_server(sd, con)
 print "Service successfully published"
else:
 print "Service could not be published because errors were found during analysis."
print arcpy.GetMessages()
0 Kudos
irishadar
New Contributor III

Hi ,

I’ve figured out the problem in the script .

I seems that all “Server Object Extensions” are enabled by default , so ,  you only have to turn the “firstChild.data” to true.

for extElement in extension.childNodes:
 # Disabled SOE.
 if extElement.tagName == 'Enabled':
 extElement.firstChild.data = 'true'

I don’t know if that is a bug or it’s supposed to be this way , but now it is working now(one script i can delete).

Still My question stays the same, does anyone know why I am getting strange massage from python announcing its success?

 

\serverName\SurveyData\Survey_Template_3.gdb\PNT_TMP_3 Successfully converted: \\serverName\PythonApp\msurvey@rashutnew.sde\PNT_TMP_3

 

thanks 

iris

0 Kudos