Error with edit_features on hosted feature service (ArcGIS 10.9.1)

1394
7
02-24-2023 03:21 AM
AtzeWitteveen
New Contributor II

I'm trying to add features through the edit_features function from the ArcGIS api for python. Every time I try this I get an error and I can't find what is causing it. 

Trying

 

vogels_fs_add_test = [{"attributes": 
                      {"waarschijnlijkheid": 0.88, 
                       "datum_observatie": 1669977330000, 
                       "x_coordinaat": 136605.4818658833, 
                       "y_coordinaat": 441738.7799215694},
                      "geometry": 
                      {"x": 136605.4818658833, "y": 441738.7799215694}}]

vogel_fs.layers.edit_features(adds=vogels_fs_add_test)

 

 

gives me the following error:

 

---------------------------------------------------------------------------
JSONDecodeError                           Traceback (most recent call last)
~\AppData\Local\ESRI\conda\envs\machine_learning\lib\site-packages\requests\models.py in json(self, **kwargs)
    970         try:
--> 971             return complexjson.loads(self.text, **kwargs)
    972         except JSONDecodeError as e:

~\AppData\Local\ESRI\conda\envs\machine_learning\lib\json\__init__.py in loads(s, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
    345             parse_constant is None and object_pairs_hook is None and not kw):
--> 346         return _default_decoder.decode(s)
    347     if cls is None:

~\AppData\Local\ESRI\conda\envs\machine_learning\lib\json\decoder.py in decode(self, s, _w)
    336         """
--> 337         obj, end = self.raw_decode(s, idx=_w(s, 0).end())
    338         end = _w(s, end).end()

~\AppData\Local\ESRI\conda\envs\machine_learning\lib\json\decoder.py in raw_decode(self, s, idx)
    354         except StopIteration as err:
--> 355             raise JSONDecodeError("Expecting value", s, err.value) from None
    356         return obj, end

JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

JSONDecodeError                           Traceback (most recent call last)
~\AppData\Local\ESRI\conda\envs\machine_learning\lib\site-packages\arcgis\gis\_impl\_con\_connection.py in _handle_response(self, resp, file_name, out_path, try_json, force_bytes, ignore_error_key)
    884                 try:
--> 885                     data = resp.json()
    886                 except JSONDecodeError:

~\AppData\Local\ESRI\conda\envs\machine_learning\lib\site-packages\requests\models.py in json(self, **kwargs)
    974             # This aliases json.JSONDecodeError and simplejson.JSONDecodeError
--> 975             raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
    976 

JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Exception                                 Traceback (most recent call last)
<ipython-input-31-1212c54b9759> in <module>
----> 1 vogel_fs_origin.edit_features(adds=vogels_fs_add_test)

~\AppData\Local\ESRI\conda\envs\machine_learning\lib\site-packages\arcgis\features\layer.py in edit_features(self, adds, updates, deletes, gdb_version, use_global_ids, rollback_on_failure, return_edit_moment, attachments, true_curve_client, session_id, use_previous_moment, datum_transformation, future)
   2958                 return EditFeatureJob(future, self._con)
   2959                 # return future
-> 2960             return self._con.post_multipart(path=edit_url, postdata=params)
   2961         except Exception as e:
   2962             if str(e).lower().find("Invalid Token".lower()) > -1:

~\AppData\Local\ESRI\conda\envs\machine_learning\lib\site-packages\arcgis\gis\_impl\_con\_connection.py in post_multipart(self, path, params, files, **kwargs)
   1160         if return_raw_response:
   1161             return resp
-> 1162         return self._handle_response(
   1163             resp=resp,
   1164             out_path=out_path,

~\AppData\Local\ESRI\conda\envs\machine_learning\lib\site-packages\arcgis\gis\_impl\_con\_connection.py in _handle_response(self, resp, file_name, out_path, try_json, force_bytes, ignore_error_key)
    886                 except JSONDecodeError:
    887                     if resp.text:
--> 888                         raise Exception(resp.text)
    889                     else:
    890                         raise

Exception: <html lang="en">

<head>
<title>Apply Edits: Locaties weidevogels (ID: 0)</title>
<link href="/arcgis/rest/static/main.css" rel="stylesheet" type="text/css"/>
</head>

<body>

<table width="100%" class="userTable">
 <tr>
 <td class="titlecell">
 ArcGIS REST Services Directory
 </td>
 <td align="right">
   
        Logged in user : portaladmin | 
        <a href="https://geo.rudutrecht.nl/arcgis/login?cmd=logout&returnUrl=https://geo.rudutrecht.nl/arcgis/rest/services">Logout</a> |
        </td>
 </tr>
</table>
<table width="100%" class="navTable">
<tr valign="top">
<td class="breadcrumbs">
<a href="/arcgis/rest/services">Home</a>

  &gt; <a href="/arcgis/rest/services">services</a>
  
  &gt; <a href="/arcgis/rest/services/Hosted">Hosted</a>
  
  &gt; <a href="/arcgis/rest/services/Hosted/Weidevogel_locaties/FeatureServer">Weidevogel_locaties (FeatureServer)</a>
  
  &gt; <a href="/arcgis/rest/services/Hosted/Weidevogel_locaties/FeatureServer/0">Locaties weidevogels</a>
  
  &gt; <a href="/arcgis/rest/services/Hosted/Weidevogel_locaties/FeatureServer/0/applyEdits"><i>applyEdits</i></a>
  </td>
<td align="right">
<a href="https://geo.rudutrecht.nl/arcgis/sdk/rest/02ss/02ss00000057000000.htm" target="_blank">Help</a> | <a href="https://geo.rudutrecht.nl/arcgis/rest/services/Hosted/Weidevogel_locaties/FeatureServer/0/applyEdits?f=help" target="_blank">API Reference</a>
</td>
</tr>
</table><h2>Apply Edits: Locaties weidevogels (ID: 0)</h2>

<div class="rbody">

<i>Note: This operation is only supported via POST</i><br/><br/>

<div style="color:#ff6666"> 
Cannot perform operation. Invalid operation parameters.<br/>
  </div><form name="sdform" action="/arcgis/rest/services/Hosted/Weidevogel_locaties/FeatureServer/0/applyEdits" method="post">

<table class="formTable">

<tr valign="top">
<td><label for="adds">Adds:</label></td>
<td>
<textarea id="adds" name="adds" rows="10" cols="55"></textarea>
</td>
</tr>

<tr valign="top">
<td><label for="updates">Updates:</label></td>
<td>
<textarea id="updates" name="updates" rows="10" cols="55"></textarea>
</td>
</tr>

<tr valign="top">
<td><label for="deletes">Deletes:</label></td>
<td><input type="text" id="deletes" name="deletes" value="" size="75"/></td>
</tr>

<tr valign="top">
<td><label for="gdbVersion">Geodatabase Version Name:</label></td>
<td><input type="text" id="gdbVersion" name="gdbVersion" value="" /></td>
</tr>

<tr valign="top">
<td>Rollback on Failure:</td>
<td>
  <label><input type="radio" name="rollbackOnFailure" value="true" checked="true" /> True &nbsp;&nbsp;</label>
  <label><input type="radio" name="rollbackOnFailure" value="false"  /> False</label>
</td>
</tr>

<tr valign="top">
<td>Use Global Ids:</td>
<td>
  <label><input type="radio" name="useGlobalIds" value="true"  /> True &nbsp;&nbsp;</label>
  <label><input type="radio" name="useGlobalIds" value="false" checked="true" /> False</label>
</td>
</tr>


<tr>
<td>Return Edit Moment:</td>
<td>
  <label><input type="radio" name="returnEditMoment" value="true"  /> True &nbsp;</label>
    <label><input type="radio" name="returnEditMoment" value="false" checked="true"  /> False</label>
</td>
</tr>

<tr>
<td>True Curve Client:</td>
<td>
  <label><input type="radio" name="trueCurveClient" value="true" checked="true" /> True &nbsp;</label>
    <label><input type="radio" name="trueCurveClient" value="false"   /> False</label>
</td>
</tr>

<tr valign="top">
<td><label for="attachments">Attachments:</label></td>
<td>
  <textarea name="attachments" id="attachments" rows="10" cols="55"></textarea>
</td>
</tr>

<tr>
<td>Time Reference UnknownClient :</td>
<td>
  <label><input type="radio" name="timeReferenceUnknownClient" value="true"  /> True &nbsp;</label>
  <label><input type="radio" name="timeReferenceUnknownClient" value="false" checked="true"  /> False</label>
</td>
</tr>
<tr valign="top">
<td>Datum Transformation:</td>
<td><input type="text" name="datumTransformation" value="" /></td>
</tr>

<tr>
<td>Async:</td>
<td>
  <label><input type="radio" name="async" value="true"  /> True &nbsp;</label>
  <label><input type="radio" name="async" value="false" checked="true"  /> False</label>
</td>
</tr>
<tr>
<td><label for="f">Format:</label></td>
<td>
<select id="f" name="f">
<option value="html">HTML</option>
<option value="pjson">JSON</option>
</select>
</td>
</tr>

<tr>
<td colspan="2" align="left">
<input type="submit" value="Apply Edits" />
</td>
</tr>

</table>

</form>

<script type="text/javascript">
document.forms.sdform.adds.focus();
</script>

</div>

<br/><br/>

</body>

</html>

 

 

The logs of the ArcGIS server manager contain the following entry when I try to use this function.

 

Hosted/Weidevogel_locaties/FeatureServer: Cannot perform operation. Invalid operation parameters.

 

 

I also tried to delete a feature by its object id.

 

vogel_fs_origin.edit_features(deletes=[12])

 

I then get the same error.

Anyone who can give me a hint to solve this? 🙂

7 Replies
Kepa
by Esri Contributor
Esri Contributor

Hello @AtzeWitteveen,

This has worked flawlessly in a development environment (10.9.1 in a hosted feature layer created from scratch):

import arcgis

vogels_fs_add_test = [{"attributes": 
                      {"waarschijnlijkheid": 0.88, 
                       "datum_observatie": 1669977330000, 
                       "x_coordinaat": 136605.4818658833, 
                       "y_coordinaat": 441738.7799215694},
                      "geometry": 
                      {"x": 136605.4818658833, "y": 441738.7799215694}}]

gis = arcgis.gis.GIS('https://gis.mydomain.local/portal', 'portaladmin', 'password')
item = gis.content.get('id')
layer = item.layers[0]
layer.edit_features(adds=vogels_fs_add_test)

Can you provide more context to your snippet?

Thanks,

AtzeWitteveen
New Contributor II

Hi Kepa,

What would you like to know? If I compare your code to mine it does exactly the same thing. If I run my code on our AGOL environment it works just fine. I found this topic https://support.esri.com/en/technical-article/000024610 where they talk about the same error as the one I'm getting. It says the error can occurs when attempting to connect to Portal for ArcGIS using the domain name server (DNS) alias and the portal is authenticating through a web-tier authentication (IWA or SAM). But I'm using a build in account, also when I share the service with everyone so you can enter data without login I still get the error.

0 Kudos
Kepa
by Esri Contributor
Esri Contributor

That's it, regarding context it's important to know how you connect to your Portal and the code you use to access the item/service. Have you tried on a newly created hosted feature layer to check if you reproduce the error? Just to be sure, I'd also check if input field names match exactly the target hosted feature layer field names.

0 Kudos
AtzeWitteveen
New Contributor II

The feature service I use was newly created specifically for this data. 

I entert some data into the FS thought the API page and that worked with this data. I also tried to delete a feature with the following code

vogel_fs_origin.edit_features(deletes=[1])

 

And that gives the same error as described before. 

0 Kudos
Kepa
by Esri Contributor
Esri Contributor

If you are able to add data through the API REST using applyEdits operation and if it fails using Python code, I'd recheck the code cause edit_features method is just an abstraction of the API REST. Also verify that the layer's url property is the same as the URL when applying edits using REST.

0 Kudos
Dani_Interrante
New Contributor II

Any updates on this? I am getting this error on edit_features(adds = x), when trying to add data from dataframe.  I've running my source dataframe through a for loop (after numerous general failures) and individually trying to add each row.  It seems to get stuck on certain rows but I can't seem to identify a pattern with the attributes/geometry of the rows I'm trying to add.  There are certain rows that consistently fail, while others only fail some of the time.  Any hints would be appreciated if you have any.  

0 Kudos
AtzeWitteveen
New Contributor II

Hi @Dani_Interrante,

For me the problem was solved when we updated our ArcGIS server to 11.1. So apparently there was something in the REST API of 10.9.1 that was blocking my request.