Select to view content in your preferred language

Layer inaccessible from Notebook

440
2
12-14-2023 05:47 AM
Labels (1)
LNX
by
New Contributor II

I have a script that imports both arcpy and arcgis modules.  It works when I run it locally in VS Code, but we need to run it as  Notebook in a specific Portal environment.  I created an Advanced Notebook since that's required to import arcpy, but the script fails on a specific arcpy function.

This code block is where the error occurs.  I'm passing the URL for a hosted feature layer into the MakeFeatureLayer function.

 

 

mission_tracks_layer = arcpy.MakeFeatureLayer_management(feature_layer.url, layer_name, where)

 

 

In the advanced Notebook it throws this error (edited to hide the actual URL):

ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000732: Input Features: Dataset https://<redacted stuff>Mission_Tracks_All/FeatureServer/3 does not exist or is not supported
Failed to execute (MakeFeatureLayer).

I got this same error previously while developing and debugging the script in VS Code.  I fixed it by launching ArcGIS Pro on the local machine which initializes the license.  After that it worked.

I find it odd that I'm facing this same error again even though I'm now running the script as an advanced Notebook within the same Portal environment where the hosted feature layer is hosted and owned.  Do I need to somehow initialize the arcpy license in the Notebook?

Things I've tried in Portal that haven't worked:

  • Made sure the hosted feature layer has editing enabled
  • Made sure the hosted feature layer is shared with the org
  • Initialized the arcgis module by logging in as the owner of the hosted feature layer

I get the same error whether I connect to the portal either of these two ways:

 

 

gis = GIS(arcgis_portal_url, owner_username, owner_password)
#or
gis = GIS("home")

 

 

 

Final thought - the reason we are needing to convert a hosted feature layer to a "local" feature layer with arcpy is because we're calling a function from arcpy.intelligence that can only operate on local data, not a hosted feature layer.

 

Thanks for your help!

Tags (3)
2 Replies
LMedeirosUI
Occasional Contributor II

@LNX Did you ever figure this out? I have a hosted feature layer collection that is publicly available but hosted on another portal than the one I need to use to run a scheduled notebook. Depending on the script I try to use, I either get "Error executing tool" or the same one your do. I can run the same script in a notebook in ArcGIS Pro (3.3) with the feature layers added to a map, but it won't work if the layers aren't added to a map. I can't figure out what's necessary to make it work in a hosted notebook... help?

0 Kudos
JessicaLott_Dymaptic
New Contributor II

You need to actually login to arcpy within the notebook. Place this code in the get started section of the script:

`

from datetime import datetime

def arcpy_SignInToPortal() -> None:
    signed_in = arcpy.SignInToPortal("notebook")
    expires = signed_in.get("expires")
    expire_time = datetime.fromtimestamp(expires)
    current_time = datetime.now()
    print("ArcPy is signed in to the current organization.\n"
          f"The token is expiring at {expire_time}.\nThe current time is {current_time}.")

arcpy_SignInToPortal()

 

Hope this helps!