<?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 arcpy featureset encoding problem in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/arcpy-featureset-encoding-problem/m-p/63064#M5111</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I've written a pythonscript that queries a mapservice layer then populates a featureset with the result and then export the attributes to an Excelfile with arcpy.TableToExcel_conversion. The problem is that once the data is loaded into the featureset any special characters like å ä ö gets messed up. How can I make sure that all characters are correct in the FeatureSet and the result Excelfile? &lt;/P&gt;&lt;P&gt;Here is some sample code that shows the problem:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;# -*- coding: utf-8 -*-


import arcpy, urllib2, os


#baseURL = arcpy.GetParametersAsText(0)
&lt;SPAN&gt;baseURL = "&lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="http://services.arcgis.com/hrh7HJqpzvUrwY6X/arcgis/rest/services/Sveriges_l%C3%A4n/FeatureServer/0" rel="nofollow noopener noreferrer" target="_blank"&gt;http://services.arcgis.com/hrh7HJqpzvUrwY6X/arcgis/rest/services/Sveriges_l%C3%A4n/FeatureServer/0&lt;/A&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;
#where = arcpy.GetParametersAsText(1)
where = "1=1"
where = urllib2.quote(where)
query = "/query?where={}&amp;amp;outFields=*&amp;amp;returnGeometry=false&amp;amp;f=json".format(where)
queryURL = baseURL + query


print queryURL
JSONrespons = urllib2.urlopen(queryURL).read()
print "JSONrespons where å ä ö displays correct: "
print JSONrespons
print "\n-----------------------------------------------------------------\n"


fs = arcpy.FeatureSet()
filename = "Table.xls"


try:
&amp;nbsp;&amp;nbsp;&amp;nbsp; fs.load(queryURL)
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "JSON extracted from recordset where å ä ö displys incorrect:"
&amp;nbsp;&amp;nbsp;&amp;nbsp; print fs.JSON
&amp;nbsp;&amp;nbsp;&amp;nbsp; try:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.TableToExcel_conversion(fs,filename)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #Excel-file from feature_set also displays å ä ö incorrect...
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; outputFile = os.path.join(arcpy.env.scratchFolder, filename)&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SetParameterAsText(2, outputFile)
&amp;nbsp;&amp;nbsp;&amp;nbsp; except Exception, e:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print e.message
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
except Exception, e:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print e.message&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 10 Dec 2021 22:24:47 GMT</pubDate>
    <dc:creator>MattiasEkström</dc:creator>
    <dc:date>2021-12-10T22:24:47Z</dc:date>
    <item>
      <title>arcpy featureset encoding problem</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-featureset-encoding-problem/m-p/63064#M5111</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I've written a pythonscript that queries a mapservice layer then populates a featureset with the result and then export the attributes to an Excelfile with arcpy.TableToExcel_conversion. The problem is that once the data is loaded into the featureset any special characters like å ä ö gets messed up. How can I make sure that all characters are correct in the FeatureSet and the result Excelfile? &lt;/P&gt;&lt;P&gt;Here is some sample code that shows the problem:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;# -*- coding: utf-8 -*-


import arcpy, urllib2, os


#baseURL = arcpy.GetParametersAsText(0)
&lt;SPAN&gt;baseURL = "&lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="http://services.arcgis.com/hrh7HJqpzvUrwY6X/arcgis/rest/services/Sveriges_l%C3%A4n/FeatureServer/0" rel="nofollow noopener noreferrer" target="_blank"&gt;http://services.arcgis.com/hrh7HJqpzvUrwY6X/arcgis/rest/services/Sveriges_l%C3%A4n/FeatureServer/0&lt;/A&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;
#where = arcpy.GetParametersAsText(1)
where = "1=1"
where = urllib2.quote(where)
query = "/query?where={}&amp;amp;outFields=*&amp;amp;returnGeometry=false&amp;amp;f=json".format(where)
queryURL = baseURL + query


print queryURL
JSONrespons = urllib2.urlopen(queryURL).read()
print "JSONrespons where å ä ö displays correct: "
print JSONrespons
print "\n-----------------------------------------------------------------\n"


fs = arcpy.FeatureSet()
filename = "Table.xls"


try:
&amp;nbsp;&amp;nbsp;&amp;nbsp; fs.load(queryURL)
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "JSON extracted from recordset where å ä ö displys incorrect:"
&amp;nbsp;&amp;nbsp;&amp;nbsp; print fs.JSON
&amp;nbsp;&amp;nbsp;&amp;nbsp; try:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.TableToExcel_conversion(fs,filename)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #Excel-file from feature_set also displays å ä ö incorrect...
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; outputFile = os.path.join(arcpy.env.scratchFolder, filename)&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SetParameterAsText(2, outputFile)
&amp;nbsp;&amp;nbsp;&amp;nbsp; except Exception, e:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print e.message
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
except Exception, e:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print e.message&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 22:24:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-featureset-encoding-problem/m-p/63064#M5111</guid>
      <dc:creator>MattiasEkström</dc:creator>
      <dc:date>2021-12-10T22:24:47Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy featureset encoding problem</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-featureset-encoding-problem/m-p/63065#M5112</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've been encountered similar problems. Have you tried this at the beginning of your code:&lt;/P&gt;&lt;P&gt;reload(sys)&lt;/P&gt;&lt;P&gt;sys.setdefaultencoding('UTF8')&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Maybe &lt;A href="http://www.ianbicking.org/illusive-setdefaultencoding.html"&gt;this&lt;/A&gt; blogpost will help you too&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Andre&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 08 May 2015 10:14:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-featureset-encoding-problem/m-p/63065#M5112</guid>
      <dc:creator>AndreV</dc:creator>
      <dc:date>2015-05-08T10:14:14Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy featureset encoding problem</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-featureset-encoding-problem/m-p/63066#M5113</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for your reply, unfortunately that didn't work. And the blogpost you mentioned is above my python skills, it didn't help me solve the problem either.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 08 May 2015 14:33:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-featureset-encoding-problem/m-p/63066#M5113</guid>
      <dc:creator>MattiasEkström</dc:creator>
      <dc:date>2015-05-08T14:33:18Z</dc:date>
    </item>
  </channel>
</rss>

