ExportToPDF crash without error on ArcGIS Server python

1302
13
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
1 Solution

Accepted Solutions
PierreloupDucroix
Frequent Contributor

I found the solution.

I tried to install ArcGIS Pro on the server to see if there was any difference, and the setup required installing Microsoft Edge WebView2 RuntimeInstaller X64.

Finally, it now works with the ArcGIS Server's python and I think it is the installation of the webview and not Pro that solved it.

I think ArcGIS Enterprise Setup should also require this webview to be installed...

CEO of MAGIS

View solution in original post

0 Kudos
13 Replies
DanPatterson
MVP Esteemed Contributor

the path exists?  (line 10) and you can write to it?

Same python version? and api for python version?


... sort of retired...
0 Kudos
PierreloupDucroix
Frequent Contributor

Here is a screenshot with a cloned environment from Pro, version 3.11.8 and PDF is written :

PierreloupDucroix_0-1720126871105.png

and here with Server's python, same version and nothing happens :

PierreloupDucroix_1-1720126933401.png

I also tried

try:
    print("try")
    mf.exportToPDF(out_pdf=r"C:\Temp\out.pdf")
except exception as e:
    print(e)

but no exception is returned

CEO of MAGIS
0 Kudos
DanPatterson
MVP Esteemed Contributor

Tech Support is your best option.

related post

Solved: Python Script succeeds in IDLE(ArcGIS Pro 2.9.0) b... - Esri Community

so there are documented issues along this vein


... sort of retired...
0 Kudos
PierreloupDucroix
Frequent Contributor

I found the solution.

I tried to install ArcGIS Pro on the server to see if there was any difference, and the setup required installing Microsoft Edge WebView2 RuntimeInstaller X64.

Finally, it now works with the ArcGIS Server's python and I think it is the installation of the webview and not Pro that solved it.

I think ArcGIS Enterprise Setup should also require this webview to be installed...

CEO of MAGIS
0 Kudos
DanPatterson
MVP Esteemed Contributor

ArcGIS Pro 3.3 system requirements—ArcGIS Pro | Documentation

there it is

WebView2 Runtime

Microsoft Edge WebView2 Runtime version 117 or later is required. If it is not already installed on the machine, use the Evergreen Bootstrapper or Evergreen Standalone Installer from Microsoft.

Note:
A per-machine installation (the default) of ArcGIS Pro requires a per-machine installation of WebView2 Runtime. To do this, right-click the WebView2 installer and click Run as administrator.


... sort of retired...
0 Kudos
PierreloupDucroix
Frequent Contributor

Thanks, Dan,

WebView2 is not part of the ArcGIS Enterprise or Server requirements (https://enterprise.arcgis.com/en/system-requirements/latest/windows/arcgis-server-system-requirement...)

but I understand that any arcpy function using an APRX will need the requirements of ArcGIS Pro and not only ArcGIS Server.

CEO of MAGIS
0 Kudos
jschuckert
Occasional Contributor

@PierreloupDucroix the "solution" below indicates issues with the ArcGIS Pro version and the requirement of webview. Is there an ACTUAL solution besides leveraging ArcGIS Server's Python version? That might not work if specific libraries need to be installed like in the case of needing to leverage a cloned Pro environment or if the machine running the code does not have AGS installed.

I have been stuck with this issue over the last 5 months with no solution. In my case, the code I have runs fine in the following 2 scenarios:

- Run from Python IDE

- Run from Task Scheduler with user logged in and using option "Run only when user is logged in" is selected

But fails in the following scenario on the exportToPDF() line when:

- Run from Task Scheduler with the option I need selected "Run whether user is logged in or not"

0 Kudos
PierreloupDucroix
Frequent Contributor

Hello,

did you check the "Run with Highest Privileges" option ?

This sound more like a privilege issue than a library issue

CEO of MAGIS
0 Kudos
jschuckert
Occasional Contributor

To follow up on this, I did some testing. In my case, my AGS version is old and does not appear have the required Python libraries to run my code which refers to a Pro project then later runs exportToPDF(). AGS is installed and running on the same server which my automation runs, like in your case, but that appears to be a dead end for me.

On another test server where I can recreate the same pdf export issue, I tried uninstalling Desktop Runtime and the WebView2 software but after Pro has already been installed. I wasn't sure if it would allow me, however it did. The export pdf still gives me issues. No change. It still fails in the last scenario:
- Run from Task Scheduler with the option I need selected "Run whether user is logged in or not"


0 Kudos