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:
public_leases = gis.content.get('item id string')
public_lease_layer = public_leases.layers[0]
source_leases = gis.content.get('item id string')
source_leases_layer = source_leases.layers[0]
source_leases_query = source_leases_layer.query(where="RecordStatus = 'Active' Or RecordStatus = 'Pending'").sdf
temp_layer = source_leases_query.spatial.to_featurelayer('temp_lease_feature_layer')
temp = temp_layer.export('temp_lease_shapefile','Shapefile')
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?