Object reference error when appending AGOL csv to hosted table.

12-13-2021 04:11 PM
New Contributor II

I need some help appending a csv to a hosted table in AGOL.   

History:   I have an exisintg hosted table published to AGOL.  I also have an uploaded csv also on AGOL (not published, just uploaded)

The hosted table has no data, only field names - it is only a shell and is editable.

The idea is that eventually the hosted table will have its values updated - via a wipe and append.  Hence the truncate.

 As a test, I'm trying to append an existing csv that has been uploaded to AGOL to this  hosted table.  

The hosted table and csv have the same field names.

When I run my script, to attempt to append the csv to the hosted table, I get an error (see below)


My input script:  (item ID's have been removed for privacy)



import os
from arcgis.gis import GIS

# Log into ArcGIS Online
gis = GIS('home')

#set AGOL item IDs
MSL_AGOL_Users_Table_ID = "AGOL item id"
input_CSV_table_ID = "AGOL item id"

#get MSL AGOL Users hosted feature service
MSL_AGOL_Users_Item = gis.content.get(MSL_AGOL_Users_Table_ID)

#Grab the MSL AGOL Users table and remove current data
UserTable = MSL_AGOL_Users_Item.tables[0]

#append CSV to hosted table
source_info_csv = gis.content.analyze(item=input_CSV_table_ID, file_type='csv', location_type='none')

UserTable.append(item_id = input_CSV_table_ID, 
                upload_format = 'csv', 
                source_info = source_info_csv, 
                append_fields=['Username', 'FullName', 'AvailableCredits', 'AssignedCredits', 'FirstName', 'LastName', 'Description', 'Email', 'IdpUsername', 'LastLogin', 'MfaEnabled', 'Access', 'StorageUsage', 'StorageQuota', 'OrgId', 'Role', 'RoleId', 'Level', 'Disabled', 'Tags', 'Region', 'Created', 'Modified', 'Provider', 'Id', 'ExistsInAD', 'ADAccountEnabled', 'ADAccountStale', 'Agency', 'Department'],




The errors I get, when executed in my ArcGIS Pro Notebook:



Exception                                 Traceback (most recent call last)
In  [109]:
Line 26:    skip_inserts=False)

File C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\features\layer.py, in append:
Line 2032:  sres = self._con.get(path=surl, params={'f' : 'json'})

File C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\gis\_impl\_con\_connection.py, in get:
Line 432:   return self._handle_response(resp, file_name, out_path, try_json, force_bytes=kwargs.pop('force_bytes', False))

File C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\gis\_impl\_con\_connection.py, in _handle_response:
Line 514:   self._handle_json_error(data['error'], errorcode)

File C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\gis\_impl\_con\_connection.py, in _handle_json_error:
Line 536:   raise Exception(errormessage)

Exception: Object reference not set to an instance of an object.
(Error Code: 400)



I've tried quite a few ways to get past this error but cannot.  

Any help to get this to work?



Tags (2)
0 Kudos
2 Replies
New Contributor II

And I should add that my ultimate goal is to upload a changing csv file and append that to the hosted table.


#input local csv
UserCSVTable = r"C:\data\sandbox\ago\output\myOutputFile.csv"

#add local csv to AGOL
temp_csv = gis.content.add({},UserCSVTable)


But I'm keeping things simple for now, to test.

0 Kudos
New Contributor II


It looks like it is having an issue with skip_inserts = False. This parameter is only used if upsert = True. According to what you are explaining you are trying to do, upsert should be True because you are trying to append new records if they don't already exist in the table.

0 Kudos