I'm attempting to overwrite a hosted layer that I own in ArcGIS Online using the arcgis.features.FeatureLayerCollection.manager.overwrite() method in Python. When I login to AGOL normally it redirects me to my organization's sign-in page so I'm using OAuth2.0 to authenticate in Python. When using my client_id and client_secret I can read my hosted layers but I'm unable to overwrite them. When attempting the below code I receive a 403 Error.
from arcgis.gis import GIS
from IPython.display import display
import os
import glob
import pandas as pd
directory = r'G:/Shared drives/path/'
file_pattern = '*.csv'
latest_file = max(glob.glob(os.path.join(directory, file_pattern)), key=os.path.getctime)
df = pd.read_csv(latest_file)
from arcgis.features import FeatureLayerCollection
gis = GIS("https://myorg.maps.arcgis.com", client_id = "XXXXXXXXXXXX", client_secret = "XXXXXXXXXXXXXX" )
fs = gis.content.get('XXXXXXXXXXXXXXXXX')
fs = FeatureLayerCollection.fromitem(fs)
fs.manager.overwrite(df)The feature layer also has editing enabled. Is it possible to overwrite or even publish a hosted feature layer using OAuth2.0 in ArcGIS API Python?
It sounds you're encountering the Limitations of application credentials which do not allow updating. You can Application logins are limited in what they can do. You can use Pro authentication to accomplish your workflow:
gis = GIS("pro")