Select to view content in your preferred language

Call ArcGis Server Service from python

771
1
03-31-2011 08:04 AM
JasonThiel
Emerging Contributor
I have seen examples of how to use python to open and manipulate an .mxd file.
Is it possible to call a service from python to do something similar? 

I have a service that contains a basemap and a business layer.  I want to call that service, locate the map to a specific extent (either through the call to the service itself or afterward in python), and then save the resulting map to a .pdf. 

Any thoughts/ideas?  Thanks.
0 Kudos
1 Reply
BruceHarold
Esri Regular Contributor
Hello Jason

Yes, you can (for example) use the service's REST endpoint from within a Python script.
Here is an example request from a tool I'm working on that batch geocodes recordset objects (what the GP service is expecting as an input parameter):


response = urllib2.urlopen(serviceEndpoint + "/submitJob?&f=json","&Record_Set="+b).read()

"b" is a RecordSet created earlier in the script.

JSON responses are easy to handle with Python, here is how I catch my GP service result:

response = urllib2.urlopen(u).read()
fDict = json.loads(response)["value"]["features"] #Yields a dictionary of JSON encoded features

"u" is a URL to each job result I loop through.

The details of your sent and received objects will be specific to your GP service, but easily determined from the REST endpoint.

Regards
0 Kudos