Python script with user input options not working in geoprocessing service

1093
7
02-24-2021 04:40 AM
JayakumarPD
Occasional Contributor

Hi,  we are using arcgis 10.4 and server also same.

We have created a arcpy script with From_date, To_date options with additional two parameters for user to enter.  In local machine and in server machine it is running, when we run in arcpy window.

But when it is published as service, it is taking time and with out any error it publishes.

when we run it with parameter, it shows message submitted...executing then it fails, giving the error ESRI type error, with out any time lag.

Is it possible to debug this gp service while running, how to put the checks to know where I am failing.

Kindly suggest. 

 

 

0 Kudos
7 Replies
jcarlson
MVP Esteemed Contributor

How exactly are the inputs being implemented? In the script itself with input()? Or are you using the script input options from w/in the program?

jcarlson_0-1614172959448.png

 

- Josh Carlson
Kendall County GIS
0 Kudos
JayakumarPD
Occasional Contributor

hi Jcarlson,

please find the attached code and kindly suggest.

0 Kudos
DavidPike
MVP Frequent Contributor

Same as jcarlson is saying, also give more info, your code, your parameters etc.

Check the arcgis server log, query->debug etc.

0 Kudos
JayakumarPD
Occasional Contributor

hi DavidPike,

please find the attached code and kindly suggest.

0 Kudos
JayakumarPD
Occasional Contributor

This is the code for reference

import arcpy
import os
import arcgisscripting
gp = arcgisscripting.create()

arcpy.env.workspace = "C:\\Users\\saslam\\AppData\\Roaming\\ESRI\\Desktop10.4\\ArcCatalog"
myDB = "Database Connections\\alias_name__server_ip_adress.sde" # sde file for database connection
sqlConn = arcpy.ArcSDESQLExecute(myDB)

# fetching parameters from gui
rangecode_param = ''
stdate_param = ''
eddate_param = ''
sectioncode_param = ''
beatcode_param = ''
tid_param = ''
forest_code_param = ''
try:
rangecode_param = arcpy.GetParameterAsText(0)
stdate_param = arcpy.GetParameterAsText(1)
eddate_param = arcpy.GetParameterAsText(2)
sectioncode_param = arcpy.GetParameterAsText(3)
beatcode_param = arcpy.GetParameterAsText(4)
tid_param = arcpy.GetParameterAsText(5)
forest_code_param = arcpy.GetParameterAsText(6)

except Exception as e:
print(e)

feature_info = []
tripid = ''
features = []
feat = []
count = 0

try:
query1 = "some sql query for mandatory inputs"
###################################################
ifelse condition lader for optional user inputs
###################################################
if sectioncode_param != '':
query1 = query1 + "and sectionCode = '"+sectioncode_param+"'"
elif beatcode_param != '':
query1 = query1 + "and beatCode = '" + beatparam + "'"
elif tid_param != '':
query1 = query1 + "and tripId = '" + tid_param + "'"

TripData = sqlConn.execute(query1)
result = TripData

tid = []
for p in result:
feature_info.append([str(p[1]), str(p[0])])
tripid = p[2]
# tid.append(str(p[2]))

features = []
for i in feature_info:
ix = float(i[0])
iy = float(i[1])
feat.append((ix, iy))


fc = "E:\\sadiq\\live proj\\working\\New Personal Geodatabase.mdb\\pat_point"
cursor = arcpy.da.InsertCursor(fc, ["SHAPE@XY", "tripid"])
for row in feat:
cursor.insertRow([row, tripid])

arcpy.env.workspace = "E:\\sadiq\\live proj\\working\\New Personal Geodatabase.mdb"

Buff = "E:\\sadiq\\live proj\\working\\New Personal Geodatabase.mdb\\new_buff_v7"
arcpy.Buffer_analysis("E:\\sadiq\\live proj\\working\\New Personal Geodatabase.mdb\\pat_point", Buff, "50 Meters", "FULL", "ROUND", "LIST", "tripid")


if forest_code_param != '':
inputfc = "Database Connections\\*******database server*******\\********database table********"
gp.Select_analysis(inputfc, "E:\\sadiq\\live proj\\working\\New Personal Geodatabase.mdb\\featureclass", "ForestCode = '"+forest_code_param+"'")
inFeatures = ["E:\\sadiq\\live proj\\working\\New Personal Geodatabase.mdb\\new_buff_v7", "E:\\sadiq\\live proj\\working\\New Personal Geodatabase.mdb\\featureclass"]
else:
inFeatures = ["E:\\sadiq\\live proj\\working\\New Personal Geodatabase.mdb\\new_buff_v7", "Database Connections\\*******database server*******\\********database table********"]

outFeatures = "E:\\sadiq\\live proj\\working\\New Personal Geodatabase.mdb\\intersect_7"
arcpy.Intersect_analysis(inFeatures, outFeatures, "")

arcpy.DeleteRows_management("E:\\sadiq\\live proj\\working\\New Personal Geodatabase.mdb\\pat_point")

except Exception as e:
print(e)

 below are some snap shots that were captured while running the script as a geoprocessing service

Capture1.PNGCapture2.PNGwhen clicked on "Check Job Details Again" displays this without even a second timelapse.when clicked on "Check Job Details Again" displays this without even a second timelapse.Capture4.PNG

kindly help resolving this
Thanks in advance

0 Kudos
DavidPike
MVP Frequent Contributor

I'll have a look through, but in the meantime you may get some better logging info by republishing (or maybe you can change in server manager?) and setting the logging to verbose or something (I cant quite remember where the option is, but there is one) this might capture a better log next time it fails.

0 Kudos
by Anonymous User
Not applicable

So, I see where you are getting the dates, but I do not see you use them anywhere in your code.  Are you using them in your sql query? Have you tried with a default value from the script and not from the geoprocessing service input?

# sets a default if the parameter comes back empty or None
stdate_param = arcpy.GetParameterAsText(1)
if stdate_param == '#' or not stdate_param:
    stdate_param = '2020-05-01'

 and here, you are concatenating the strings together

query1 = "some sql query for mandatory inputs"
    ###################################################
      ifelse condition lader for optional user inputs
    ###################################################
    if sectioncode_param != '':
        query1 = query1 + "and sectionCode = '"+sectioncode_param+"'"

 will make your query1 end up like:

"some sql query for mandatory inputs and sectionCode = '"+sectioncode_param+"'"

Unless you took it out to post on the forum since you mentioned that it works as a script...

Last thing I can think of as is, can the server you have this process on use the myDB connection (username/password, SSO, etc)- i.e., its not tied to your login so it only works when you are logged in?

0 Kudos