Brandon.Davis@slc.ca.gov_CSLC

Issue with ArcGIS API for Python Append Function in AGOL Notebooks Beta

Discussion created by Brandon.Davis@slc.ca.gov_CSLC on May 29, 2020

Hi all,

 

Wondering if anybody else had this issue: when using the append function from the python API, I receive an "Object reference not set to an instance of an object" error. The weird part is I've gotten the code to work previously after getting the error, then today went I went in to make some adjustments, it stopped working all the sudden. The previous reason I was getting the error had to do with the field names not matching, but that has since been corrected (since I'm appending from a shapefile, I had to account for truncated field names). While troubleshooting, I used the exact same code from within the python window in ArcGIS Pro and it appeared to work, which makes me think something else is going on here.

 

Here is the code in question:

# get public lease feature layer
public_leases = gis.content.get('item id string')

# get specific sublayer from public lease feature layer
public_lease_layer = public_leases.layers[0]

# get source lease data
source_leases = gis.content.get('item id string')

# get source lease layer
source_leases_layer = source_leases.layers[0]

# Query for only Active, Pending Leases as a spatial data frame
source_leases_query = source_leases_layer.query(where="RecordStatus = 'Active' Or RecordStatus = 'Pending'").sdf

# Publish the spatial data frame as a feature layer, will also publish a shapefile
temp_layer = source_leases_query.spatial.to_featurelayer('temp_lease_feature_layer')

# Export temporary layer to shapefile
temp = temp_layer.export('temp_lease_shapefile','Shapefile')

# append public lease layer with records from temp shapefile (SLC Properties) using upsert
public_lease_layer.append(
    item_id=temp.id,
    upload_format='shapefile',
    upsert=True,
    update_geometry=True,
    use_globalids=True,
    field_mappings=[
        {
            'name': 'RecordStatus',
            'source' : 'RecordStat'},
        {
            'name': 'LeaseNum',
            'source' : 'LeaseNum'},
        {
            'name': 'GeneralLocation',
            'source' : 'GeneralLoc'},
        {
            'name': 'LeaseorPermit',
            'source' : 'LeaseorPer'},
        {
            'name': 'TypeofLease',
            'source' : 'TypeofLeas'},
        {
            'name': 'LeaseStartDate',
            'source' : 'LeaseStart'},
        {
            'name': 'LeaseExpirationDate',
            'source' : 'LeaseExpir'},
        {
            'name': 'SLCApprovalDate',
            'source' : 'SLCApprova'},
        {
            'name': 'MinuteItem',
            'source' : 'MinuteItem'},
        {
            'name': 'Improvements',
            'source' : 'Improvemen'},
        {
            'name': 'Latitude',
            'source' : 'Latitude'},
        {
            'name': 'Longitude',
            'source' : 'Longitude'}])

 

And here is the error I get:

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-13-93b5922cf27b> in <module>
     43         {
     44             'name': 'Longitude',
---> 45             'source' : 'Longitude'}])

/opt/conda/lib/python3.6/site-packages/arcgis/features/layer.py in append(self, item_id, upload_format, source_table_name, field_mappings, edits, source_info, upsert, skip_updates, use_globalids, update_geometry, append_fields, rollback, skip_inserts, upsert_matching_field)
   1456             sres = self._con.get(path=surl, params={'f' : 'json'})
   1457             while sres['status'].lower() != "completed":
-> 1458                 sres = self._con.get(path=surl, params={'f' : 'json'})
   1459                 if sres['status'].lower() in "failed":
   1460                     break

/opt/conda/lib/python3.6/site-packages/arcgis/_impl/connection.py in get(self, path, params, ssl, compress, try_json, is_retry, use_ordered_dict, out_folder, file_name, force_bytes, add_token, token)
    900                                     return self.get(path=path, params=params, ssl=True, compress=compress, try_json=try_json, is_retry=True)
    901
--> 902                             self._handle_json_error(resp_json['error'], errorcode)
    903                             return None
    904                 except AttributeError:

/opt/conda/lib/python3.6/site-packages/arcgis/_impl/connection.py in _handle_json_error(self, error, errorcode)
   1201
   1202         errormessage = errormessage + "\n(Error Code: " + str(errorcode) +")"
-> 1203         raise RuntimeError(errormessage)
   1204
   1205 class _StrictURLopener(request.FancyURLopener):

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

 

Thoughts? am I missing something?

Outcomes