Hello all. I'm attempting a script to append records from an ArcGIS Online feature layer to a local geodatabase feature class. I want to run the script nightly as a scheduled task. The below works well when I have Pro open and am logged into ArcGIS Online as my Portal. It fails when I run it as a stand alone script, saying the hosted feature layer does not exist or is not supported. Any advice how to accomplish the append properly? Thanks very much in advance.
import arcpy
from arcgis import GIS
#connect to ArcGIS Online
agol = GIS(username="username",password="password")
#find the hosted feature layer
item = agol.content.get("6ceffb124830415a9149e7c965e0fd12")
lyr = item.layers[0].url
#reference the geodatbase feature class
fc = r"C:\temp\gdb.sde\GISDB.GIS.TARGET_FC"
#empty the feature class
arcpy.management.TruncateTable(fc)
#append from the feature layer to the feature class
arcpy.Append_management(lyr, fc, "NO_TEST")