ExportToPDF crash without error on ArcGIS Server python

1370
14
Jump to solution
07-04-2024 02:48 AM
PierreloupDucroix
Frequent Contributor

Hello,

I try to export a PDF with a scheduled task that runs in an arcgis server's server.

The ExportToPDF line of code crashes without any error with the python from ArcGIS Server, but works great with the python from ArcGIS Pro in other environments...

Here is a simple code test I made, it's crashing in the last line :

 

import arcpy
aprx = arcpy.mp.ArcGISProject(r"D:\path...\exportToPDF.aprx")
m = aprx.listMaps("Map")[0]
layout ="Test"
lyt = aprx.listLayouts(layout)[0]
mf = lyt.listElements("mapframe_element", "WEBMAP_MAP_FRAME")[0]
extent = arcpy.Extent(446998.96875,  214866.71875, 446579.875, 215163.046875)
mf.camera.setExtent(extent)
m.defaultCamera = mf.camera
lyt.exportToPDF(out_pdf=r"D:\path...\out.pdf")

 

 

Working with Pro 3.3

Not working with Server 11.3

Any idea ?

 

CEO of MAGIS
14 Replies
PierreloupDucroix
Frequent Contributor

FYI I was referring to the second option below in addition to the first :

PierreloupDucroix_0-1744250970545.png

Maybe you should consider login a case to Esri support

 

CEO of MAGIS
0 Kudos
jschuckert
Regular Contributor

Correct, I had both those options checked with highest privileges checked in all my tests. Then when testing, I can successfully get the script to fully run when the user is logged on and using the "Run only when user is logged on" option however once toggled to (what I need) "Run whether user is logged on or not" the script fails at the exportToPDF() line of code. 

This same code had been running without issue for 1 1/2 years then started failing around late November/early December. 

I did initially have an ESRI case open however it has since been closed. ESRI was not able to recreate the behavior. I can recreate it on 3 different servers in my environment. 

I may reopen the case however as I have now found a few different threads related to the issue:

https://community.esri.com/t5/arcgis-pro-questions/exporttopdf-with-arcpy-fails/m-p/1594183

https://community.safe.com/automation-13/flow-jobs-failing-on-python-script-using-exporttopdf-36967

@PierreloupDucroix , did you find a solution or use the workaround of leveraging AGS's Python environment? 

0 Kudos
PierreloupDucroix
Frequent Contributor

In my case, using AGS's python environment after installing the webview runtime did work.

Are you sure the Webview has been installed with elevated privileges (run installer as administrator) ?

Maybe you could try to run the installer as the scheduled tasks user in order to be sure it is installed for this user...

CEO of MAGIS
0 Kudos
jschuckert
Regular Contributor

Interesting. 

I will try re-installing to be sure, however I am pretty familiar with the installs so that should be the case (ran as admin). 

On the second test server I have available to me I installed and am testing Task Scheduler from my own admin login. So not leveraging the task scheduler (service) user account and still have the issue.

This has a been a hard issues to troubleshoot 😣 

0 Kudos
jschuckert
Regular Contributor

I performed more troubleshooting related to the install however I am still unfortunately stuck with no resolution on this. I have been working with our IT Department and tried opening a new ESRI case however no luck in either avenue. For the new ESRI case, I provided several new links related to the issue (this page for example) but they came back stating it must be a Windows based issue per the Task Scheduler behavior when selecting "run whether use is logged in or not" when running the task.

Has anyone found a solution to this? 

0 Kudos