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
Nothing seems to make a difference, I only get the same:
OSError: C:\\GPTools\\files\\GPTools.aprx
Did the licensing change at all when you made the layout changes?
No, there has not been any difference in license.
try os.path.exists to check if the file exists and os.access to check if you have read permission for the file.
import os
file_path = r"C:/GPTools/files/GPTools.aprx"
if os.path.exists(file_path) and os.access(file_path, os.R_OK):
print("File exists and is readable")
else:
print("File does not exist or is not readable")
When you say, "only when I run the tool through ArcGIS Server" are you referring to the python installation on the server machine?
Where you ever able to get this resolved? we are having the same issue...
Same issue in 10.9.1 . arcpy.Exists(), os.path.exists() and os.path.isfile() return true for the path, but it won't load and throws the OSError. Service is running through a conda environment.
In 11.0 it doesn;t throw the error, but it doesn't run properly either.
However, this makes me wonder if it is related to the aprx version. I have Pro 3.1 and I think 10.9.1 errors as it only handles up the 2.9 apparently .
I think you are right, but we did try to downgrade back to 2.9.5 and still got the same OS error. The web page below says we should be able to do it as we are only two versions back (we are on 10.9.1 and trying to publish with 3.1.2). We are working with tech support to get some type of confirmation. I may try downgrading again to 2.9.1 instead of 2.9.5.
So it looks like its a version compatibility issue. I swapped out the aprx for an older one I had from 2021 (not sure if its 2.9.1 or 2.9.5) and I do not get the OS Error. We are going to test 2.9.1 and see if we get past the error and then again at 2.9.5. The first person who posted - it would be interesting to know if maybe the 2.9.X version changed (the dot - dot version) when you started seeing the error.