<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to edit a feature class used in a Feature Service via Python? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/how-to-edit-a-feature-class-used-in-a-feature/m-p/234207#M18167</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Do you need to perform a process of some kind on the data?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If your doing a wholesale update, delete/append will work around locks&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.management.DeleteRows()&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.management.Append()&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Or perhaps arcpy.da.InsertCursor just update a few rows?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You can also open an edit session using arcpy and perform many a gp tasks. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;We would need to know more about what your trying to accomplish.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 23 Aug 2013 18:16:19 GMT</pubDate>
    <dc:creator>JamesGustine</dc:creator>
    <dc:date>2013-08-23T18:16:19Z</dc:date>
    <item>
      <title>How to edit a feature class used in a Feature Service via Python?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-edit-a-feature-class-used-in-a-feature/m-p/234206#M18166</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm experimenting around a bit with ArcGIS for Server and I have a feature class that I'd like to edit with a python script.&amp;nbsp; The catch is that this feature class is the basis for a Feature Service I have published.&amp;nbsp; Does anyone know what the best approach is for editing these features via arcpy?&amp;nbsp; I initially thought I could simpy overwrite the feature class, but I fear server will place a lock on it.&amp;nbsp; Is it possible to delete or add new features through a POST operation, or do I have the wrong idea?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I essentially have a feature class of polygons used in a feature service and I want to execute a python script every couple of minutes with Windows Task Scheduler that updates it.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any advice is definitely welcome!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;- Nick&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 23 Aug 2013 13:29:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-edit-a-feature-class-used-in-a-feature/m-p/234206#M18166</guid>
      <dc:creator>NickJacob</dc:creator>
      <dc:date>2013-08-23T13:29:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit a feature class used in a Feature Service via Python?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-edit-a-feature-class-used-in-a-feature/m-p/234207#M18167</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Do you need to perform a process of some kind on the data?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If your doing a wholesale update, delete/append will work around locks&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.management.DeleteRows()&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.management.Append()&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Or perhaps arcpy.da.InsertCursor just update a few rows?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You can also open an edit session using arcpy and perform many a gp tasks. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;We would need to know more about what your trying to accomplish.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 23 Aug 2013 18:16:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-edit-a-feature-class-used-in-a-feature/m-p/234207#M18167</guid>
      <dc:creator>JamesGustine</dc:creator>
      <dc:date>2013-08-23T18:16:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit a feature class used in a Feature Service via Python?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-edit-a-feature-class-used-in-a-feature/m-p/234208#M18168</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You should be able to 'truncate' (delete the rows) and append even if ArcGIS Server has it published as &lt;/SPAN&gt;&lt;STRONG&gt;jgustine&lt;/STRONG&gt;&lt;SPAN&gt; mentioned. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have created a few python tools that will update a feature service using the POST method by interacting with the &lt;/SPAN&gt;&lt;A href="http://services.arcgisonline.com/ArcGIS/SDK/REST/index.html?catalog.html"&gt;ArcGIS Server REST API&lt;/A&gt;&lt;SPAN&gt;.&amp;nbsp; We used the The python script uses the &lt;/SPAN&gt;&lt;A href="http://docs.python.org/2/library/httplib.html"&gt;httplib &lt;/A&gt;&lt;SPAN&gt;and creates either an HTTPSConnection or HTTPConnection object (depending if it is HTTP or HTTPS access).&amp;nbsp; My code essentially does something like this: &lt;/SPAN&gt;&lt;BR /&gt;&lt;OL&gt;&lt;BR /&gt;&lt;LI&gt;Inspect the URL.&amp;nbsp; Determine if HTTP or HTTPS to build the correct connection object&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;Inspect the &lt;A href="http://resources.arcgis.com/en/help/rest/apiref/serverInfo.html"&gt;security configuration&lt;/A&gt;.&amp;nbsp; If token based (&lt;STRONG&gt;isTokenBasedSecurity = True&lt;/STRONG&gt;)&lt;A href="http://resources.arcgis.com/en/help/rest/apiref/generatetoken.html"&gt;obtain a token&lt;/A&gt; by prompting for username/password.&amp;nbsp; If IWA then attempt the following and assume the user running the tool has access&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;Convert the records from the Feature Class to a JSON object using the &lt;A href="http://resources.arcgis.com/en/help/main/10.1/index.html#//018z0000005r000000"&gt;arcpy.FeatureSet&lt;/A&gt; tool and accessing the JSON property.&amp;nbsp; &lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;Obtain all of the primary keys in the feature set object (iterating through the JSON object).&amp;nbsp; &lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;&lt;A href="http://resources.arcgis.com/en/help/rest/apiref/fsquery.html"&gt;Query the feature service&lt;/A&gt; to determine if these are adds or updates&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;if its not in the feature service create a &lt;A href="http://resources.arcgis.com/en/help/rest/apiref/feature.html"&gt;feature object &lt;/A&gt;for the 'adds' parameter for each record not found in the service.&amp;nbsp; &lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;If it is in the feature service create a &lt;A href="http://resources.arcgis.com/en/help/rest/apiref/feature.html"&gt;feature object&lt;/A&gt; for the 'updates' parameter for each record found in the service.&amp;nbsp; &lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;Execute an &lt;A href="http://resources.arcgis.com/en/help/rest/apiref/fsedits.html"&gt;HTTP post method to the &lt;STRONG&gt;applyEdits&lt;/STRONG&gt; operation&lt;/A&gt; with the adds and updates specified as parameters&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;Inspect the result, store it as an IN_MEMORY table and return it to the user&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;&lt;/LI&gt;&lt;BR /&gt;&lt;/OL&gt;&lt;BR /&gt;&lt;SPAN&gt;It actually performs very fast.&amp;nbsp; Here were a few things/problems that I ran into while developing these tools: &lt;/SPAN&gt;&lt;BR /&gt;&lt;UL&gt;&lt;BR /&gt;&lt;LI&gt;The arcpy.FeatureSet.JSON property would return strings in unicode.&amp;nbsp; The HTTP Post did not like that.&amp;nbsp; Had to convert all string types to str before creating the Feature Object&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;Had some issues with arcpy.FeatureSet missing/truncating the geometries as posted &lt;A href="http://forums.arcgis.com/threads/85489-arcpy.FeatureSet-Missing-(truncated)-JSON-result?highlight=FeatureSet"&gt;here&lt;/A&gt;&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;If token based authentication then we needed to prompt the user for credentials.&amp;nbsp; We used the &lt;STRONG&gt;&lt;A href="http://docs.python.org/2/library/getpass.html"&gt;getpass&lt;/A&gt;&lt;/STRONG&gt; library in a sub-process as discussed &lt;A href="http://forums.arcgis.com/threads/37576-encrypting-a-password-parameter"&gt;here&lt;/A&gt;&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;There is a max size limit imposed on the POST method.&amp;nbsp; I think it is something like 2MB.&amp;nbsp; Cannot seem to find information about it off the top of my head but you might run in this if there is a lot of changes/updates.&amp;nbsp; Might need to split the job into small chunks.&amp;nbsp; Process like 10% at a time and run the POST 10 times...&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;&lt;/LI&gt;&lt;BR /&gt;&lt;/UL&gt;&lt;BR /&gt;&lt;SPAN&gt;So a basic workflow would look like this: &lt;/SPAN&gt;&lt;BR /&gt;&lt;UL&gt;&lt;BR /&gt;&lt;LI&gt;Usesr use ArcMap to extract some data from a Feature Service to a local Feature Class&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;Update records desired&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;Insert new records as desired&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;Run a python script tool to sync the features to the feature service using the applyEdits operation (POST)&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;&lt;/LI&gt;&lt;BR /&gt;&lt;/UL&gt;&lt;BR /&gt;&lt;SPAN&gt;Hope this helps.&amp;nbsp; I might be able to show you a few code samples if you really wanted them but I've got all the logic rolled up into a robust set of classes to interact with ArcGIS Server.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 27 Aug 2013 20:56:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-edit-a-feature-class-used-in-a-feature/m-p/234208#M18168</guid>
      <dc:creator>PF1</dc:creator>
      <dc:date>2013-08-27T20:56:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit a feature class used in a Feature Service via Python?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-edit-a-feature-class-used-in-a-feature/m-p/234209#M18169</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thank you both for your replies! I learned quite a bit from both responses.&amp;nbsp; So far I've used a combination of arcpy's Truncate Table and Append tools with some good results.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 02 Sep 2013 00:04:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-edit-a-feature-class-used-in-a-feature/m-p/234209#M18169</guid>
      <dc:creator>NickJacob</dc:creator>
      <dc:date>2013-09-02T00:04:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit a feature class used in a Feature Service via Python?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-edit-a-feature-class-used-in-a-feature/m-p/234210#M18170</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I am also interested in adding data to AGOL through Python. I have scripts to download data but require assistance in the upload of new data. I am having problems executing an HTTP post method to the applyEdits with ADDS or addFeatures operation though REQUEST or URLIB2. Is it possible for pfoppe to post some of his code to assist, it would be well appreciated.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Cheers rossco&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 Nov 2013 21:44:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-edit-a-feature-class-used-in-a-feature/m-p/234210#M18170</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2013-11-04T21:44:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit a feature class used in a Feature Service via Python?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-edit-a-feature-class-used-in-a-feature/m-p/234211#M18171</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Rossco, &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I've attached a snippet of the UML class diagram of my implementation for reference, and a little snippet of code that might help you (although you will not be able to run this since you do not have all the underlying classes...).&amp;nbsp; Hopefully just seeing the parameters on the request will help.&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Most of the times that I run into a problem it is because there is a unicode string somewhere in the json structure... and I have not yet figured out a way to get a POST to work when there is a unicode in there, thats why I built a few of my own objects (AgsFeature, AgsFeatures, AgsGeometry, ...) to remove those unicode characters...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This runs against a sample server that Esri has available for editing capabilities...&amp;nbsp; I created a new record with a 'rotation' equal to 42 (&lt;/SPAN&gt;&lt;A href="http://en.wikipedia.org/wiki/42_(number)" rel="nofollow noopener noreferrer" target="_blank"&gt;since 42 is the answer to life&lt;/A&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;

from datetime import datetime
from ArcServer.ArcGisServer import AgsLayer
from ArcServer.ArcGisServer import AgsFeatureServiceLayer
from ArcServer.ArcGisServer import AgsFeature
from ArcServer.ArcGisServer import AgsSpatialReference



#Build a layer object to query
print "\n\n****QUERYING SERVICE***"
ags_fs_url=r'http://sampleserver6.arcgisonline.com/arcgis/rest/services/Wildfire/FeatureServer/0'
lyrObj=AgsLayer.fromUrl(ags_fs_url)

#Find the record for NFL Broncos...
where="rotation=42"
result=lyrObj.query(where,"*",geometry=True)
print "Query Result: %s"%str(result)
print "Response JSON: \n%s"%str(lyrObj.json())

#Try to add the date to the description
print "\n\n****TRYING TO ADD THE DATE WITH UNICODE CHARACTERS***"
jdata=lyrObj.json()
feature=jdata["features"][0]
dt=datetime.strftime(datetime.now(),"%Y%m%d_%H:%M:%S")
old_desc=feature['attributes']['description']
new_desc="Go Broncos! @ %s"%dt
print "Setting description from '%s' to '%s'"%(old_desc,new_desc)
feature['attributes']['description']=new_desc

fslyrObj=AgsFeatureServiceLayer.fromUrl(ags_fs_url)
fslyrObj.params=dict()
fslyrObj.params['updates']=[feature]
fslyrObj.params['f']='json'
pth="/applyEdits"


print "Executing 'applyEdits' via POST..."
print "Host: %s"%str(fslyrObj.host)
print "Path: %s"%str(fslyrObj.path+pth)
print "Method: %s"%str(fslyrObj.method)
print "port: %s"%str(fslyrObj.port)
print "https: %s"%str(fslyrObj.https)
print "headers: %s"%str(fslyrObj.headers)
print "params: %s"%str(fslyrObj.params)

result=fslyrObj.execute(pth)
print "Query Result: %s"%str(result)
print "Query Messages: %s"%str(fslyrObj.messages())
print "Query Data: %s"%str(fslyrObj.data())


#Lets try without unicode...
print "\n\n****TRYING TO ADD THE DATE WITHOUT UNICODE CHARACTERS***"
srObj=AgsSpatialReference.fromFeatureSetSr(jdata['spatialReference'])
featureObj=AgsFeature.fromFsFeature(feature,jdata['spatialReference'])


del fslyrObj
fslyrObj=AgsFeatureServiceLayer.fromUrl(ags_fs_url)
fslyrObj.params=dict()
fslyrObj.params['updates']=featureObj.json()
fslyrObj.params['f']='json'
pth="/applyEdits"

print "Executing 'applyEdits' via POST..."
print "Host: %s"%str(fslyrObj.host)
print "Path: %s"%str(fslyrObj.path+pth)
print "Method: %s"%str(fslyrObj.method)
print "port: %s"%str(fslyrObj.port)
print "https: %s"%str(fslyrObj.https)
print "headers: %s"%str(fslyrObj.headers)
print "params: %s"%str(fslyrObj.params)

result=fslyrObj.execute(pth)
print "Query Result: %s"%str(result)
print "Query Messages: %s"%str(fslyrObj.messages())
print "Query Data: %s"%str(fslyrObj.data())

&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;And... Output: &lt;/SPAN&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;&lt;BR /&gt;&lt;BR /&gt;****QUERYING SERVICE***&lt;BR /&gt;Query Result: True&lt;BR /&gt;Response JSON: &lt;BR /&gt;{u'features': [{u'geometry': {u'y': 4828807.519031979, u'x': -11690778.563894253}, u'attributes': {u'description': u'Go Broncos! @ 20131105_08:52:52', u'objectid': 1609, u'eventtype': 12, u'created_user': u'', u'created_date': 1383664073000L, u'rotation': 42, u'last_edited_date': 1383666772000L, u'eventdate': 0, u'last_edited_user': u''}}], u'fields': [{u'alias': u'OBJECTID', u'type': u'esriFieldTypeOID', u'name': u'objectid'}, {u'alias': u'Rotation', u'type': u'esriFieldTypeSmallInteger', u'name': u'rotation'}, {u'alias': u'Description', u'length': 75, u'type': u'esriFieldTypeString', u'name': u'description'}, {u'alias': u'Date', u'length': 36, u'type': u'esriFieldTypeDate', u'name': u'eventdate'}, {u'alias': u'Type', u'type': u'esriFieldTypeInteger', u'name': u'eventtype'}, {u'alias': u'created_user', u'length': 255, u'type': u'esriFieldTypeString', u'name': u'created_user'}, {u'alias': u'created_date', u'length': 36, u'type': u'esriFieldTypeDate', u'name': u'created_date'}, {u'alias': u'last_edited_user', u'length': 255, u'type': u'esriFieldTypeString', u'name': u'last_edited_user'}, {u'alias': u'last_edited_date', u'length': 36, u'type': u'esriFieldTypeDate', u'name': u'last_edited_date'}], u'spatialReference': {u'wkid': 102100, u'latestWkid': 3857}, u'geometryType': u'esriGeometryPoint', u'objectIdFieldName': u'objectid', u'globalIdFieldName': u''}&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;****TRYING TO ADD THE DATE WITH UNICODE CHARACTERS***&lt;BR /&gt;Setting description from 'Go Broncos! @ 20131105_08:52:52' to 'Go Broncos! @ 20131105_09:01:36'&lt;BR /&gt;Executing 'applyEdits' via POST...&lt;BR /&gt;Host: sampleserver6.arcgisonline.com&lt;BR /&gt;Path: /arcgis/rest/services/Wildfire/FeatureServer/0/applyEdits&lt;BR /&gt;Method: POST&lt;BR /&gt;port: 80&lt;BR /&gt;https: False&lt;BR /&gt;headers: {'Content-type': 'application/x-www-form-urlencoded', 'Accept': 'text/plain'}&lt;BR /&gt;params: {'updates': [{u'geometry': {u'y': 4828807.519031979, u'x': -11690778.563894253}, u'attributes': {u'description': 'Go Broncos! @ 20131105_09:01:36', u'objectid': 1609, u'eventtype': 12, u'created_user': u'', u'created_date': 1383664073000L, u'rotation': 42, u'last_edited_date': 1383666772000L, u'eventdate': 0, u'last_edited_user': u''}}], 'f': 'json'}&lt;BR /&gt;Query Result: False&lt;BR /&gt;Query Messages: ['Response indicated there was an error, please check the obj.data()...']&lt;BR /&gt;Query Data: {"error":{"code":400,"message":"Unable to complete operation.","details":[]}}&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;****TRYING TO ADD THE DATE WITHOUT UNICODE CHARACTERS***&lt;BR /&gt;Executing 'applyEdits' via POST...&lt;BR /&gt;Host: sampleserver6.arcgisonline.com&lt;BR /&gt;Path: /arcgis/rest/services/Wildfire/FeatureServer/0/applyEdits&lt;BR /&gt;Method: POST&lt;BR /&gt;port: 80&lt;BR /&gt;https: False&lt;BR /&gt;headers: {'Content-type': 'application/x-www-form-urlencoded', 'Accept': 'text/plain'}&lt;BR /&gt;params: {'updates': [{'geometry': {'y': '4828807.51903', 'x': '-11690778.5639', 'spatialReference': {'wkid': 102100, 'latestWkid': 3857}}, 'attributes': {'DESCRIPTION': 'Go Broncos! @ 20131105_09:01:36', 'OBJECTID': 1609, 'EVENTTYPE': 12, 'CREATED_USER': '', 'CREATED_DATE': 1383664073000L, 'ROTATION': 42, 'LAST_EDITED_DATE': 1383666772000L, 'EVENTDATE': 0, 'LAST_EDITED_USER': ''}}], 'f': 'json'}&lt;BR /&gt;Query Result: True&lt;BR /&gt;Query Messages: []&lt;BR /&gt;Query Data: {"addResults":[],"updateResults":[{"objectId":1609,"success":true}],"deleteResults":[]}&lt;BR /&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you post your parameters on your HTTP Post (and the description of the service) it might help...&amp;nbsp; Best of luck!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 11:50:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-edit-a-feature-class-used-in-a-feature/m-p/234211#M18171</guid>
      <dc:creator>PF1</dc:creator>
      <dc:date>2021-12-11T11:50:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit a feature class used in a Feature Service via Python?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-edit-a-feature-class-used-in-a-feature/m-p/234212#M18172</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Ok... Ok... I created a better sample that you should be able to run (without all my custom classes, error checking, validation, etc).&amp;nbsp; This runs on my environment with just the base python installation for ArcGIS 10, 10.1 or 10.2.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import httplib
import urllib
import json
from urlparse import urlparse
from datetime import datetime



def parseUrl(url):
 result=dict()
 up=urlparse(url)
 host=up.netloc
 #assume port 80 at first
 port=80
 #result["host"]=host
 result["path"]=up.path
 result["https"]=False
 if (up.scheme.upper()=='HTTPS'):
&amp;nbsp; result["https"]=True
&amp;nbsp; #switch to port 443 if HTTPS by default
&amp;nbsp; port=443
 #accept non-default port if provided...
 if (up.netloc.find(":") != -1):
&amp;nbsp; port=int(host[host.find(":")+1:])
&amp;nbsp; host=host[0:host.find(":")]
 result["host"]=host
 result["port"]=port
 return result


ags_fs_url=r'http://sampleserver6.arcgisonline.com/arcgis/rest/services/Wildfire/FeatureServer/0'
urlp=parseUrl(ags_fs_url)
headers={"Content-type": "application/x-www-form-urlencoded","Accept": "text/plain"}


print "\n\n****QUERYING SERVICE***"

conn=httplib.HTTPConnection(urlp['host'],urlp['port'])
params=dict()
params['f']='json'
params['where']="rotation=42"
params['outFields']="objectid,description,rotation"
params['returnGeometry']=False
conn.request("POST",urlp['path']+"/query",urllib.urlencode(params),headers)
resp=conn.getresponse()
data=resp.read()
jdata=json.loads(data)
print "Response JSON: \n%s"%str(jdata)


#Try to add the date to the description
print "\n\n****TRYING TO ADD THE DATE WITH UNICODE CHARACTERS***"
feature=jdata["features"][0]
dt=datetime.strftime(datetime.now(),"%Y%m%d_%H:%M:%S")
old_desc=feature['attributes']['description']
new_desc="Go Broncos! @ %s"%dt
print "Setting description from '%s' to '%s'"%(old_desc,new_desc)
feature['attributes']['description']=new_desc

conn=httplib.HTTPConnection(urlp['host'],urlp['port'])
params=dict()
params['f']='json'
params['updates']=[feature]
conn.request("POST",urlp['path']+"/applyEdits",urllib.urlencode(params),headers)
resp=conn.getresponse()
data=resp.read()
jdata=json.loads(data)
print "Request Parameters: \n%s"%str(params)
print "Response JSON: \n%s"%str(jdata)

#Lets try without unicode...
print "\n\n****TRYING TO ADD THE DATE WITHOUT UNICODE CHARACTERS***"
new_feature=dict()
for k in feature.keys():
 new_feature[str(k)]=dict()

for k in feature['attributes'].keys():
 if type(feature['attributes']&lt;K&gt;) == unicode:
&amp;nbsp; new_feature['attributes'][str(k)]=str(feature['attributes']&lt;K&gt;)
 else:
&amp;nbsp; new_feature['attributes'][str(k)]=feature['attributes']&lt;K&gt;

conn=httplib.HTTPConnection(urlp['host'],urlp['port'])
params=dict()
params['f']='json'
params['updates']=[new_feature]
conn.request("POST",urlp['path']+"/applyEdits",urllib.urlencode(params),headers)
resp=conn.getresponse()
data=resp.read()
jdata=json.loads(data)
print "Request Parameters: \n%s"%str(params)
print "Response JSON: \n%s"%str(jdata)
&lt;/K&gt;&lt;/K&gt;&lt;/K&gt;&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG style="text-decoration: underline;"&gt;And the output:&lt;/STRONG&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;****QUERYING SERVICE***&lt;BR /&gt;Response JSON: &lt;BR /&gt;{u'fields': [{u'alias': u'OBJECTID', u'type': u'esriFieldTypeOID', u'name': u'objectid'}, {u'alias': u'Rotation', u'type': u'esriFieldTypeSmallInteger', u'name': u'rotation'}, {u'alias': u'Description', u'length': 75, u'type': u'esriFieldTypeString', u'name': u'description'}], u'globalIdFieldName': u'', u'objectIdFieldName': u'objectid', u'features': [{u'attributes': {u'rotation': 42, u'description': u'Go Broncos! @ 20131105_12:33:55', u'objectid': 1609}}]}&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;****TRYING TO ADD THE DATE WITH UNICODE CHARACTERS***&lt;BR /&gt;Setting description from 'Go Broncos! @ 20131105_12:33:55' to 'Go Broncos! @ 20131105_12:38:14'&lt;BR /&gt;Request Parameters: &lt;BR /&gt;{'updates': [{u'attributes': {u'rotation': 42, u'description': 'Go Broncos! @ 20131105_12:38:14', u'objectid': 1609}}], 'f': 'json'}&lt;BR /&gt;Response JSON: &lt;BR /&gt;{u'error': {u'message': u'Unable to complete operation.', u'code': 400, u'details': []}}&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;****TRYING TO ADD THE DATE WITHOUT UNICODE CHARACTERS***&lt;BR /&gt;Request Parameters: &lt;BR /&gt;{'updates': [{'attributes': {'rotation': 42, 'description': 'Go Broncos! @ 20131105_12:38:14', 'objectid': 1609}}], 'f': 'json'}&lt;BR /&gt;Response JSON: &lt;BR /&gt;{u'addResults': [], u'deleteResults': [], u'updateResults': [{u'success': True, u'objectId': 1609}]}&lt;BR /&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;BTW... GO Broncos!!&amp;nbsp; &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 11:50:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-edit-a-feature-class-used-in-a-feature/m-p/234212#M18172</guid>
      <dc:creator>PF1</dc:creator>
      <dc:date>2021-12-11T11:50:30Z</dc:date>
    </item>
  </channel>
</rss>

