Select to view content in your preferred language

Arcpy.mp.ArcGISProject() gives an OSError, but didn't earlier

2968
10
11-10-2022 04:01 AM
by Anonymous User
Not applicable

I have made a project that creates map prints from different layouts in ArcGIS Pro and published them as Services in ArcGIS Server 10.9.1.

The python code obviously uses a reference to an ArcGIS Pro project file (.aprx) to reference the layouts further. This have worked fine so far, but lately I changed some of the layouts in the .aprx file and now I always get the OSError, with the filepath specified.

Well that means, only when I run the tool through ArcGIS Server. When I run the tool through ArcGIS Pro directly or via the Python interpreter in PyCharm it works fine. And also, before I changed the .aprx everything worked fine in ArcGIS Server as well.

Here is some of the code used to reference the file:

 

 

exceptionMsg = "";
arcgisProjectFile = None
pth = r"C:/GPTools/files/GPTools.aprx"
try:
    arcgisProjectFile = mp.ArcGISProject(pth)
except Exception as ex:
    template = "En 'Exception' av typen {0} skjedde under genereringen. Kodemeldinger:\n{1!r}"
    exceptionMsg = template.format(type(ex).__name__, ex.args)
spatialReference = arcpy.SpatialReference(25832)

 

 


I've tried

  • renaming the file,
  • changing the location,
  • getting rid of any spaces or special characters in the path,
  • using realstring,
  • not using realstring
  • using escape characters
  • Moving the folder inside the Python-environment
  • Taking the folder outside of the Python-environment
  • Putting the path in variable
  • Writing the path explicitly in the function call
  • Writing backslash
  • Writing forwardslash

Nothing seems to make a difference, I only get the same:

OSError: C:\\GPTools\\files\\GPTools.aprx

0 Kudos
10 Replies
JamesBotterill4
Occasional Contributor

I encountered this oserror trying to exportToPDF. I found it was because the folder I was exporting, didn't exist and as such the serviceaccount running the process, didn't have access. I needed the serviceaccount to mkdir first

Unfortunately none of the error handling such as arcpy.Exists(), os.path.exists() and os.path.isfile() pointed me to this

0 Kudos