How to resolve encoding errors in python geoprocessing?

2198
1
Jump to solution
09-06-2013 02:20 AM
ab1
by
Occasional Contributor II
I have a simple python script that reads a string from a text file and inserts it into an Oracle database.

When I run the script with Eclipse using Pydev plugin I get no error and the message is inserted into database.

However, when I run the script using an ArcGIS geoprocessing service (using a toolbox), I get the following error in the logs, and no insertion is performed into database:

[06/09/2013-10:30:39.380] ERROR - APPLICATION <module>(<type 'exceptions.UnicodeEncodeError'>, UnicodeEncodeError('ascii', u"INSERT INTO APPLI.ALERT (ID_ALERT,MESSAGE,TYPE_ALERT) values(1617.0,q'[Les coordonn\xe9es ne sont pas correctes\n]',3)", 94, 95, 'ordinal not in range(128)'))


The code is the following:

try:     msg=open("myFile.log", 'r')     a=msg.read(20)      strInsert = "INSERT INTO  APPLI.ALERT(ID_ALERT,MESSAGE,TYPE_ALERT) values(1625.0,'"+a.replace('\"','').decode('utf-8')+"',3)"     logger_module.debug(str(strInsert))     SdeExecuteSQL(CONNEXION_FILE,strInsert ) except:     python_error_handler()


When I open myFile.log with Notepad++ the encoding is ANSI as UTF-8.

Do you have any hint?

Regards.
0 Kudos
1 Solution

Accepted Solutions
ab1
by
Occasional Contributor II
I found the answer: The problem comes from logger_module.debug(str(strInsert)) I deleted str() and everything runs correctly now with logger_module.debug(strInsert)

Do you have any idea why it worked in Eclipse but not in ArcGIS Server?

View solution in original post

0 Kudos
1 Reply
ab1
by
Occasional Contributor II
I found the answer: The problem comes from logger_module.debug(str(strInsert)) I deleted str() and everything runs correctly now with logger_module.debug(strInsert)

Do you have any idea why it worked in Eclipse but not in ArcGIS Server?
0 Kudos