I have a python script that works. I've put it into a toolbox, run it and it works. I make it into a geoprocessing service and it fails. I cannot figure out why. The script pulls up a data driven page mxd, creates the mapbook, exports it as a pdf. I don't understand why the geoprocessing service doesn't work. It fails. Does anyone have an idea as to why?
Thanks
Please post some more information:
-the exact error message (turn message level to INFO at the gp service level and run it again from Desktop to get the error messages
-possibly post your script
-have you registered your MXD folder with the datastore? You dont have to, but in this case its probably a good idea.
I've registered all the data sources with the server. It's like I said, the script executes from toolbox without issues. It's only after becoming a service that it fails. The service is Asynchronous.
My error message just says: Failed.
Here is the script:
import arcpy,os,uuid,datetime
#path to template mxds
mxdPath = r"C:\regional_service_data\Cook\Mapbooks\ElectricUtilitiesMapbook.mxd"
titleMXD = r"C:\regional_service_data\Cook\Mapbooks\ElectricUtilitiesIndexPage.mxd"
#Build PDF File Name
pdfFileName = "ElecMap_" + str(uuid.uuid4()) + ".pdf"
outputPath = arcpy.env.scratchWorkspace
if not outputPath:
outputPath = r"C:\arcgisserver\directories\arcgisoutput"
OutputFile = os.path.join(outputPath, pdfFileName)
arcpy.AddMessage("Creating Title Page...")
#open title page mxd and set title text
titlePage = arcpy.mapping.MapDocument(titleMXD)
#export title page to pdf - well use to append to the ddp pdf
tempTitlePDFPath = os.path.join(outputPath,"titlePage.pdf")
arcpy.mapping.ExportToPDF(titlePage, tempTitlePDFPath)
del titlePage
#Reference the map document
arcpy.AddMessage("Initializing MapBook...")
mxd = arcpy.mapping.MapDocument(mxdPath)
#reference the DataDrivenPages
ddp = mxd.dataDrivenPages
#export DDP to pdf
arcpy.AddMessage("Exporting PDF...")
ddp.exportToPDF(OutputFile,"ALL","","PDF_SINGLE_FILE",300,"FASTER","RGB",True,"ADAPTIVE","RASTERIZE_BITMAP",True,"NONE",True,80)
arcpy.AddMessage("PDF Created")
arcpy.AddMessage("Appending Pages")
#ddp index and title pages
finalPDF = arcpy.mapping.PDFDocumentOpen(OutputFile)
finalPDF.insertPages(tempTitlePDFPath,1)
arcpy.AddMessage("Saving PDF")
finalPDF.saveAndClose()
#make outputfile available to gp clients
arcpy.SetParameterAsText(0, OutputFile)
arcpy.AddMessage("Cleaning Up")
#Clean up
del mxd
del finalPDF
os.remove(tempTitlePDFPath)
arcpy.AddMessage("Done")
Is you server on the same machine which you have desktop on? The reason why I ask is that you have a couple of paths to your c:\ eg:
C:\regional_service_data\Cook\Mapbooks\ElectricUtilitiesMapbook.mxd
Can your server see the same path? Try using a UNC path to the same area in your python script
Regards
Anthony
These two lines stand out to me right away:
mxdPath = r"C:\regional_service_data\Cook\Mapbooks\ElectricUtilitiesMapbook.mxd"
titleMXD = r"C:\regional_service_data\Cook\Mapbooks\ElectricUtilitiesIndexPage.mxd"
Server cannot access directories unless you register them. Instead of hard coding them make them input parameters and let server copy the map documents to where it puts the GP data.
Your tool probably cannot access the mxds.
Hope this helps.
Andrew
I would try republishing the GP tool with logging at the info level and repost the error with the additional detail. I had a similar problem where I had a 3rd party module that wasn't installed in the 64bit python folder on each of the servers.
I had this same problem with one of the ESRI samples and when I made it Synchronous it worked fine.
What I found was that I had to have some sort of input for the geoprocessing service to work. Once I created an input, the service worked.