Select to view content in your preferred language

project_service_aprx_object.save() Error from Pro 2.8.x to 2.9 upgrade

9014
22
Jump to solution
11-23-2021 02:26 PM
Min-DongChang
Occasional Contributor

I have a code that a developer created that no long works for me.  With a recent upgrade from 2.8.x to 2.9, the script no errors out at a line " project_service_aprx_object.save()".  What I believe the code is trying to do update the source of feature layers in a map ("1_Service_Status_On").  However, when it comes to the  project_service_aprx_object.save() line, it gives me the following error:

Traceback (most recent call last):
File "<string>", line 686, in <module>
File "A:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\_mp.py", line 285, in save
return convertArcObjectToPythonObject(self._arc_object.save(*gp_fixargs((), True)))
OSError: G:\SDE_User_Connections\Projects\UnitedStates\US_Test01\Web_Services\Test01_Project_Services.aprx

I'm running the code in an empty APRX file so I don't even have the Test01_Project_Services.aprx open.  I'm a novice at python so any I can provide more of the code if necessary.

0 Kudos
22 Replies
RahulGupta2
New Contributor

I encountered the same problem. To resolve the issue I used the following code.

#Remove existing layer from original template
Original_Template = r"C:\TempScript\original.aprx"
aprx = arcpy.mp.ArcGISProject(Original_Template)
aprxMap = aprx.listMaps("Map")
for lyr in aprxMap[0].listLayers():
      aprxMap[0].removeLayer(lyr)

#Add new layer to original template
_layer = arcpy.MakeFeatureLayer_management(fc,"LayerName").getOutput(0)
aprxMap[0].addLayer(_layer,"BOTTOM")
aprx.saveACopy(r"C:\TempScript\Temp_Template.aprx")

#Save original template to the temp template as aprx.save() is not working
aprx_tmp = arcpy.mp.ArcGISProject(r"C:\TempScript\Temp_Template.aprx")
aprxMap_tmp = aprx_tmp.listMaps("Map")
m = aprxMap_tmp[0]
sddraft = m.getWebLayerSharingDraft("FEDERATED_SERVER", "MAP_IMAGE", "LayerName")

Regards

Rahul

0 Kudos
VincentLantaca
Occasional Contributor

seems like there are still issues with aprx.save() even in 3.1, I can run a geoprocessing script with modifies then saves an .aprx file once after opening ArcGIS Pro, but the same script a second time will give the OSError until I re-open Pro

ASw93
by
Regular Contributor

Can confirm I am seeing this same error still in 3.1.