AnsweredAssumed Answered

arcpy featureset encoding problem

Question asked by mattias_j on Jan 21, 2015
Latest reply on May 8, 2015 by mattias_j

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?

Here is some sample code that shows the problem:

 

# -*- coding: utf-8 -*-


import arcpy, urllib2, os


#baseURL = arcpy.GetParametersAsText(0)
baseURL = "http://services.arcgis.com/hrh7HJqpzvUrwY6X/arcgis/rest/services/Sveriges_l%C3%A4n/FeatureServer/0"
#where = arcpy.GetParametersAsText(1)
where = "1=1"
where = urllib2.quote(where)
query = "/query?where={}&outFields=*&returnGeometry=false&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:
    fs.load(queryURL)
    print "JSON extracted from recordset where å ä ö displys incorrect:"
    print fs.JSON
    try:
        arcpy.TableToExcel_conversion(fs,filename)
        #Excel-file from feature_set also displays å ä ö incorrect...
        outputFile = os.path.join(arcpy.env.scratchFolder, filename)  
        arcpy.SetParameterAsText(2, outputFile)
    except Exception, e:
        print e.message
    
except Exception, e:
    print e.message

Outcomes