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

1382
9
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
9 Replies
by Anonymous User
Not applicable

Did the licensing change at all when you made the layout changes?

 

 

0 Kudos
by Anonymous User
Not applicable

No, there has not been any difference in license.

0 Kudos
gismovals
New Contributor

Did you resolve this? I'm having the same issue with Server 11 and Pro 3.0.3.

DannyMcVey
Esri Contributor

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")
0 Kudos
JS3
by
New Contributor

When you say, "only when I run the tool through ArcGIS Server" are you referring to the python installation on the server machine?

0 Kudos
mattprice
New Contributor II

Where you ever able to get this resolved? we are having the same issue...

0 Kudos
GrantHerbert
Occasional Contributor II

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 . 

0 Kudos
mattprice
New Contributor II

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.

https://pro.arcgis.com/en/pro-app/latest/help/analysis/geoprocessing/share-analysis/geoprocessing-se...

0 Kudos
mattprice
New Contributor II

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.

0 Kudos