<?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: addFeature to Feature Server using python in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/addfeature-to-feature-server-using-python/m-p/70977#M5801</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I manage to get the following to work with a username an password.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If someone knows how to get the current users credentials and pass that instead it would be most helpful.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;import urllib, urllib2&lt;/P&gt;&lt;P&gt;from ntlm import HTTPNtlmAuthHandler&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;user = 'DOMAIN\user'&lt;/P&gt;&lt;P&gt;password = "password"&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;url = "&lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="http://" rel="nofollow" target="_blank"&gt;http://&lt;/A&gt;&lt;SPAN&gt;&amp;lt;server&amp;gt;/arcgis/rest/services/Test/FeatureServer/0/addFeatures"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;updateAttr = [{ "geometry" : {"x" : XXX,"y" : XXX},"attributes" : {"COMMENTS" : "WORK"}}]&lt;/P&gt;&lt;P&gt;params = urllib.urlencode({'f': 'json', 'features': updateAttr})&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;passman = urllib2.HTTPPasswordMgrWithDefaultRealm()&lt;/P&gt;&lt;P&gt;passman.add_password(None, url, user, password)&lt;/P&gt;&lt;P&gt;# create the NTLM authentication handler&lt;/P&gt;&lt;P&gt;auth_NTLM = HTTPNtlmAuthHandler.HTTPNtlmAuthHandler(passman)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;# create and install the opener&lt;/P&gt;&lt;P&gt;opener = urllib2.build_opener(auth_NTLM)&lt;/P&gt;&lt;P&gt;urllib2.install_opener(opener)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;url1 = urllib2.Request(updateBaseURL,params)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;# retrieve the result&lt;/P&gt;&lt;P&gt;response = urllib2.urlopen(url1)&lt;/P&gt;&lt;P&gt;print(response.read())&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 23 Jun 2015 06:24:43 GMT</pubDate>
    <dc:creator>ElliottCarson</dc:creator>
    <dc:date>2015-06-23T06:24:43Z</dc:date>
    <item>
      <title>addFeature to Feature Server using python</title>
      <link>https://community.esri.com/t5/python-questions/addfeature-to-feature-server-using-python/m-p/70976#M5800</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm trying to add a feature to a Feature Server using python without any success.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When running the script I get the following error HTTPError: HTTP Error 401: Unauthorized.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The service only requires windows authentication of a user logged into the network, the service does not require a username or password.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How can this be achieved in Python?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My code so far is:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;add = [{ "geometry" : {"x" : 20.8,"y" : -115.5},"attributes" : {"COMMENTS" : "Test"}}]&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;service_url = r"&lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="http://" rel="nofollow" target="_blank"&gt;http://&lt;/A&gt;&lt;SPAN&gt;&amp;lt;servername&amp;gt;/ags/rest/services/test/testlyr/FeatureServer/"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;/P&gt;&lt;P&gt;params = urllib.urlencode({'f': 'json', 'features': add})&amp;nbsp; &lt;/P&gt;&lt;P&gt;req = urllib2.Request("{0}/addFeatures/?".format(service_url, params))&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;/P&gt;&lt;P&gt;response = urllib2.urlopen(req)&amp;nbsp; &lt;/P&gt;&lt;P&gt;jsonResult = json.load(response)&amp;nbsp; &lt;/P&gt;&lt;P&gt;print jsonResult&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Elliott&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 22 Jun 2015 08:45:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/addfeature-to-feature-server-using-python/m-p/70976#M5800</guid>
      <dc:creator>ElliottCarson</dc:creator>
      <dc:date>2015-06-22T08:45:44Z</dc:date>
    </item>
    <item>
      <title>Re: addFeature to Feature Server using python</title>
      <link>https://community.esri.com/t5/python-questions/addfeature-to-feature-server-using-python/m-p/70977#M5801</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I manage to get the following to work with a username an password.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If someone knows how to get the current users credentials and pass that instead it would be most helpful.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;import urllib, urllib2&lt;/P&gt;&lt;P&gt;from ntlm import HTTPNtlmAuthHandler&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;user = 'DOMAIN\user'&lt;/P&gt;&lt;P&gt;password = "password"&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;url = "&lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="http://" rel="nofollow" target="_blank"&gt;http://&lt;/A&gt;&lt;SPAN&gt;&amp;lt;server&amp;gt;/arcgis/rest/services/Test/FeatureServer/0/addFeatures"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;updateAttr = [{ "geometry" : {"x" : XXX,"y" : XXX},"attributes" : {"COMMENTS" : "WORK"}}]&lt;/P&gt;&lt;P&gt;params = urllib.urlencode({'f': 'json', 'features': updateAttr})&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;passman = urllib2.HTTPPasswordMgrWithDefaultRealm()&lt;/P&gt;&lt;P&gt;passman.add_password(None, url, user, password)&lt;/P&gt;&lt;P&gt;# create the NTLM authentication handler&lt;/P&gt;&lt;P&gt;auth_NTLM = HTTPNtlmAuthHandler.HTTPNtlmAuthHandler(passman)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;# create and install the opener&lt;/P&gt;&lt;P&gt;opener = urllib2.build_opener(auth_NTLM)&lt;/P&gt;&lt;P&gt;urllib2.install_opener(opener)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;url1 = urllib2.Request(updateBaseURL,params)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;# retrieve the result&lt;/P&gt;&lt;P&gt;response = urllib2.urlopen(url1)&lt;/P&gt;&lt;P&gt;print(response.read())&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 23 Jun 2015 06:24:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/addfeature-to-feature-server-using-python/m-p/70977#M5801</guid>
      <dc:creator>ElliottCarson</dc:creator>
      <dc:date>2015-06-23T06:24:43Z</dc:date>
    </item>
  </channel>
</rss>

