Select to view content in your preferred language

Publish ExtractData using python, works from Pro GUI, but not on the command line

1012
4
02-07-2022 09:15 AM
JoëlHempenius3
Frequent Contributor

I'm trying to automate publishing the ExtractData task as Geoprocessing Service. To do this, I created a small Python Script which executes the ExtractData Tool and then it should publish the result object as a Geoproccesing Service. The input to the script comes from an ArcGIS Pro Project, I tried it with a layer from my Enterprise Geodatabase and with a layer from the default project file geodatabase. Everytime I run the script from the commandline, it fails with the Error 999999, however, when I run the script from the python console within ArcGIS Pro, it runs fine.

JolHempenius3_0-1644254017469.png

 

 

import arcpy, sys, getopt, os

#modify this function to run your toolbox

    # Run the tool and set to a result object
inputaprx = 'C:\\Users\\joelh\Documents\\ArcGIS\\Projects\\TestExtract\\TestExtract.aprx'
aprx = arcpy.mp.ArcGISProject(inputaprx)
#aprx = arcpy.mp.ArcGISProject("CURRENT") #voor gebruik in ArcGIS Pro
outputfile = 'C:\\Users\\joelh\Documents\\ArcGIS\\Projects\\TestExtract\\extract.zip'
mp = aprx.listMaps("*")[0]
layers = mp.listLayers("*")
sddraft = "testservice.sddraft"
sd = "testservice.sd"
serviceName = "ExtractData"
connection_file_path = "server.ags"
copyData = True
servicefolder = "Test"
summary  = "Extract Data"
tags = "Tag"
executionType =  "Asynchronous"
serverURL = "https://my.arcgis.enterprise/server"

    
arcpy.AddMessage("Executing Extract task")
result = arcpy.server.ExtractData(layers, layers[0], "File Geodatabase - GDB - .gdb", "ESRI GRID - GRID", "Same As Input", None, outputfile)
#result = arcpy.server.ExtractDataTask(layers, layers[0], "File Geodatabase - GDB - .gdb", "ESRI GRID - GRID", outputfile)
    
arcpy.AddMessage("Extract task message count {}".format(result.messageCount))
arcpy.AddMessage("Messages: {}".format(result.getMessages(0)))
arcpy.AddMessage("Warning Messages: {}".format(result.getMessages(1)))
arcpy.AddMessage("Error Messages: {}".format(result.getMessages(2)))

server_type = "FROM_CONNECTION_FILE"
analyzeMessages = arcpy.CreateGPSDDraft(
            result, sddraft, serviceName, server_type=server_type,connection_file_path = connection_file_path,
            copy_data_to_server=copyData, folder_name=servicefolder,
            summary=summary, tags=tags, executionType=executionType,
            resultMapServer=False, showMessages="INFO", maximumRecords=5000,
            minInstances=1, maxInstances=1, maxUsageTime=100, maxWaitTime=10,
            maxIdleTime=180)
arcpy.AddMessage("Messages {}".format(analyzeMessages))
if analyzeMessages['errors'] == {}:
    # Execute StageService
    arcpy.StageService_server(sddraft, sd)
arcpy.UploadServiceDefinition_server(sd, serverURL)

 

 

 

Any ideas why this script fails on the command line?

-Joël Hempenius.

Languages: JavaScript, Python and Dunglish
0 Kudos
4 Replies
DanPatterson
MVP Esteemed Contributor

Is there code missing since... 

inputaprx = 'TestExtract.aprx'

won't work on its own.  Either set the workspace or provide the full path to the project.

The python console inside pro and notebooks inside pro know about where things are (hence... CURRENT works)


... sort of retired...
0 Kudos
JoëlHempenius3
Frequent Contributor

Hi Dan,

Small mistake of me there, I tried it both with the full path to the Aprx file and this example I tried to see if a relative path would make a difference. It didn't however, so the question remains why it doesn't work from the command line.
I will correct the sample code to include the full path

Thanks.

-Joël Hempenius.

Languages: JavaScript, Python and Dunglish
0 Kudos
DanPatterson
MVP Esteemed Contributor

Stage Service (Server)—ArcGIS Pro | Documentation

The only thing I can see on a quick look is that your paths are still not specific

From their code example

arcpy.StageService_server(r"C:\Data\World.sddraft", r"C:\Data\World.sd")

Have you set your environment workspace somewhere so that the referenced files can be located? (eg arcpy.env.workspace = ....


... sort of retired...
0 Kudos
JoëlHempenius3
Frequent Contributor

Fixed those as well. 

Still no luck:

JolHempenius3_0-1644423122553.png

It's now telling me there's an error somewhere, but I print both the messages from the Extract Task and from the staging and there isn't an error before it fails (or I need glasses, because I don't see it anymore)

-Joël Hempenius.

Languages: JavaScript, Python and Dunglish
0 Kudos