Using ArcPy to Overwrite Hosted Feature Service Fails

551
2
12-10-2021 10:08 AM
LucasMurray2
Occasional Contributor II

I developed an arcpy script that includes overwriting a hosted feature service in Portal with data from a csv file.  The script ran just fine in ArcGIS Enterprise version 10.8.1 but I recently upgraded to 10.9.1 and it fails.  The script was written using Python 3.7.  Below is a copy of my script and attached is a log file.  Notice everything works fine up until manager.overwrite.  Did something change in 10.9.1 that is causing this to fail?

 

from arcgis.gis import GIS
from arcgis.features import *
import pandas as pd
import logging

#--------------PARAMETERS--------------
csv = r'\\MyServer\Events.csv' #CSV file that will be overwritten with updates from JSON
jsonEvents = 'https://TheJsonFile' #JSON file location on web
eventID = 'xxxx' #ID of feature layer in portal that will be overwritten.
portal = 'https://MyServer.azdes.gov/portal'
portalUID = 'UserName'
portalPWD = 'Password'


#------------Process----------------

#Create log file
logging.basicConfig(filename='logEvents.log', filemode='w', level=logging.INFO)

try:
    logging.info("Process Started")

    #Read JSON URL and copy to csv file
    df = pd.read_json(jsonEvents) #reads JSON file
    df.to_csv(csv,index=False,header=True)  #Writes json events to csv file
    logging.info('CSV Updated')

    #Log in to portal
    gis = GIS(url = portal, username = portalUID, password = portalPWD)
    logging.info('Logged in to Portal')

    #Identify the feature layer that will be overwritten and convert to feature layer collection
    fsEvents = gis.content.get(eventID)
    flcEvents = FeatureLayerCollection.fromitem(fsEvents)
    logging.info("Feature Layer Collection created")

    #Overwrite the feature layer collection with results from the csv
    flcEvents.manager.overwrite(csv)
    logging.info("Overwrite Successful.  End Process")

except:
    logging.exception('Process failed')
    raise

 

  

Tags (3)
0 Kudos
2 Replies
TonyContreras_Frisco_TX
Occasional Contributor III

Are you attempting to update a single layer within a hosted service, or all the data for the entire service?  Have you verified that the following requirements have been met for the existing Feature Service + incoming data?

  1. Only hosted feature layer collection services can be overwritten

  2. The original data used to publish this layer should be available on the portal

3. The data file used to overwrite should be of the same format and filename as the original that was used to publish the layer  - If you originally uploaded a .zip file, your script will have to zip up the file(s) and overwrite with the new zip file.

4. The schema (column names, column data types) of the data_file should be the same as original. You can have additional or fewer rows (features).

Here is more information on that method:

FeatureLayerCollectionManager.overwrite 

0 Kudos
LucasMurray2
Occasional Contributor II

Thanks for your reply.  Yes, the file meets all of those criteria.  Plus, the python code above was working with ArcGIS Enterprise 10.8.1 but not with 10.9.1.

0 Kudos