Select to view content in your preferred language

Portal data with stand alone script?

1414
10
Jump to solution
09-01-2022 11:25 AM
AustinBachurski
New Contributor III

I'm trying to automate some workflow that happens weekly.  Got everything working except for removing the old and uploading the new data at the end.  When done manually in ArcGIS Pro this is done using the Delete Features tool, then the Append tool.  I put a model together to chain the two, I can run the model in Pro using the Python window and it works fine, but when I transfer the code to my script and run it stand alone it fails with a "ERROR 000732: Target Dataset: Dataset LayerName does not exist or is not supported"  - the layer is hosted on our enterprise portal, so I thought maybe I needed to  use 

 

 

from arcgis.gis import GIS
gis = GIS("http://my.portal.address/", "username", "password")
LayerName = gis.content.get('f6f63262826e40adbc34e8d01ff9b3aa')

 

 

But this also fails with a 

"""

File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py", line 4241, in DeleteFeatures
raise e
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py", line 4238, in DeleteFeatures
retval = convertArcObjectToPythonObject(gp.DeleteFeatures_management(*gp_fixargs((in_features,), True)))
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\_base.py", line 512, in <lambda>
return lambda *args: val(*gp_fixargs(args, True))
RuntimeError: Object: Error in executing tool

"""

I've tried entering everything into a Jupyter Notebook and viewing the file after assigning the portal path and it is displaying as expected, but I can't go any farther without errors.  If I use a local path and file everything works fine, and I've tried a few different layers from our portal and they all produce the same error.  Hoping for some help, thank you.

0 Kudos
10 Replies
AustinBachurski
New Contributor III

I was finally able to get it figured out late last night with some help from Esri support and a lot of googling, the syntax to login to the portal with a stand alone script is different than the syntax used in a notebook, which is what I was using previously (I think)...   So this section was totally unnecessary.

from arcgis.gis import GIS
gis = GIS("http://my.portal.address/", "username", "password")
LayerName = gis.content.get('f6f63262826e40adbc34e8d01ff9b3aa')

 

After removing that I just had to add this to the code prior to trying to interact with the portal item.

arcpy.SignInToPortal(arcpy.GetActivePortalURL(), 'USERNAME', 'PASSWORD')

 

Then I had to change the target for the file to the web address for the map server.  I did have to add a "/0" to the end of the web address, if I'm honest I'm not sure why that is - guessing it selects the specific layer in the feature?  Not sure, but it wouldn't work without it...

CrimeWebData = "https://portal.address/FeatureServer/0"

 

After making those changes it works as expected.  Thanks for the help!