Select to view content in your preferred language

How to use a web geoprocessing service

3341
4
07-23-2015 10:11 AM
WesMiller
Deactivated User

I'm trying to use a web geoprocessing service in python. I'm using the example in this web site http://resources.arcgis.com/en/help/main/10.1/index.html#/Using_a_geoprocessing_service_in_Python_sc...

I'm not getting the expected results does anyone know the proper syntax to submit a job to a geoprocessing service?

Here's my code:

import arcpy,urllib,json


baseURL = "my service here"

query = "?Address:=504 Walnut St & RecType: = Youth Baseball League?"




submitResponse = urllib.urlopen(baseURL+query)
submitResponse = urllib.urlopen(baseURL+query)
jobUrl = submitResponse.geturl()
status = "esriJobSubmitted"
print jobUrl
while status == "esriJobSubmitted" or status == "esriJobExecuting":
    #print "checking to see if job is completed..."
    time.sleep(1)
    jobResponse = urllib.urlopen(jobUrl, "f=json")
    jobJson = json.loads(jobResponse.read())
    if 'jobStatus' in jobJson:
        status = jobJson['jobStatus']
        if status == "esriJobSucceeded":
            if 'results' in jobJson:
                resultsUrl = jobUrl + "/results/"
                resultsJson = jobJson['results']
                for paramName in resultsJson.keys():
                    resultUrl = resultsUrl + paramName
                    print resultUrl
                    resultResponse = urllib.urlopen(resultUrl, "f=json")
                    resultJson = json.loads(resultResponse.read())
                    print resultJson['value']
                    print resultJson
                    
        if status == "esriJobFailed":
            if 'messages' in jobJson:
                print jobJson['messages']
    else:
        print "no jobId found in the response"
    print "no jobId found in the response"


Message was edited by: Wes Miller

0 Kudos
4 Replies
FreddieGibson
Honored Contributor

Are you wanting to use python to make a REST call to the GPService or are you wanting to import the GPService as a tool within arcpy and allow arcpy to handle the rest call?

0 Kudos
WesMiller
Deactivated User

I'm wanting to use python to make a REST call to the GPService

0 Kudos
JonathanQuinn
Esri Notable Contributor

You can submit it directly at the REST endpoint with Fiddler or the browser's developer tools running to capture the traffic when sending the request, while making sure it actually runs successfully there.  Then, construct the request including parameters within Python to match what Fiddler or the dev tools returned.

0 Kudos
WesMiller
Deactivated User

Thanks for the reply Jonathan Quinn​ I was able to get it working by changing to synchronous with the code below

url = "myservice?"
param = "Address=324 W Evans St&RecType=Youth Soccer League&f=json"
submitResponse = urllib.urlopen(url+param)
print submitResponse.read()
0 Kudos