I have created a Geoprocessing service that is hosted on a server inside our firewall (ArcGIS Enterprise 10.6). The GP service adds messages via arcpy.AddMessage("msg").

Locally, I import the toolbox via arcpy.ImportToolbox("https://...") and execute the service. Everything runs to completion, but I would like to receive messages back from the service to my local python script.

Calling arcpy.GetMessages() from my local python script only returns local messages.

Is there anyway to get the messages from the server-side GP service?

Edit: when I run the GP service from ArcCatalog (as a tool) it returns all of the remote messages.

  • You have to enable messages in the Server and the service, but you can retrieve them through the REST API.
    – Vince
    Feb 7 '19 at 19:09
  • @Vince in the service parameters, Message Level = Info. Where do you enable messages in the Server?
    – Brad
    Feb 7 '19 at 19:12
  • You only need to set message level = info on the service to get AddMessage level messages to display.
    – KHibma
    Feb 7 '19 at 19:24
  • @KHibma messages do display if run via Desktop. When I import and run via python, no messages are returned from arcpy.GetMessages
    – Brad
    Feb 7 '19 at 19:28

To get the messages of the Geoprocessing Service, you need to do two things:

  1. Ensure you have a proper message level set on the service. AddMessage = Info, AddWarning = Warning, AddError = Error. (This traverses down, meaning Info will display warnings and errors).
  2. You need to perform GetMessage off the result of your execution.

From your question, you've stated you're calling arcpy.GetMessages(). You need to call GetMessages from the result of your execution.

From the using gp services with python help, you can see the execution is assigned to result and getMessages() is called from that. Of course you'd need to wrap this in a print statement: print(result.getMessages()

import arcpy
import time

arcpy.ImportToolbox("http://sampleserver1.arcgisonline.com/ArcGIS/services;Elevation/ESRI_Elevation_World", "viewshedAlias")

result = arcpy.Viewshed_viewshedAlias(r'c:\data\inputPoint.shp', "10000 Kilometers")

while result.status < 4:
       print result.status
print "Execution Finished"

arcpy.CopyFeatures_management(result.getOutput(0), 'localResult.shp')
  • I had 2 issues: 1) I was not calling GetMessages from the result (as you mentioned). 2) I was calling GetMessages before the result status was 4. so adding the "while" loop was also important.
    – Brad
    Feb 11 '19 at 12:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.