| Issue 62: | the error message is not unicode on chinese system? | |
| 2 people starred this issue and may be notified of changes. | Back to list |
i try to excute a error sql statement.
the error raised by pyodbc on chiese Windows system is not unicode.
i use this function to decode the message to chinese.
def decodeErrorMessage(e):
s = repr(e)
s = s.replace("'","\\'")
s = s.replace('"',"\\\"")
s = eval('"'+s+'"')
return s.decode('gbk').encode('utf-8')
is that a problem of pyodbc?
the message return by pyodbc when i try to connect to MS SqlServer 2008
Chinese Edition.
ProgrammingError: ('42000', '[42000] [Microsoft][ODBC SQL Server
Driver][SQL Ser
ver]\xce\xde\xb7\xa8\xb4\xf2\xbf\xaa\xb5\xc7\xc2\xbc\xcb\xf9\xc7\xeb\xc7\xf3\xb5
\xc4\xca\xfd\xbe\xdd\xbf\xe2
"iSatServerDB"\xa1\xa3\xb5\xc7\xc2\xbc\xca\xa7\xb0\
xdc\xa1\xa3 (4060) (SQLDriverConnectW); [42000] [Microsoft][ODBC SQL Server
Driv
er][SQL
Server]\xce\xde\xb7\xa8\xb4\xf2\xbf\xaa\xb5\xc7\xc2\xbc\xcb\xf9\xc7\xeb\
xc7\xf3\xb5\xc4\xca\xfd\xbe\xdd\xbf\xe2
"iSatServerDB"\xa1\xa3\xb5\xc7\xc2\xbc\x
ca\xa7\xb0\xdc\xa1\xa3 (4060)')
Jul 15, 2009
Project Member
#1
mkleehammer
Status:
Investigating
Aug 7, 2009
All exceptions in Python 2.x use ANSI strings so pyodbc does also. I'm currently using the ANSI version of SQLGetDiagRec to retreive the error. The Python 3.x version will obviously use Unicode for everything, so that'll help. In the meantime, I'm not exactly sure what the best approach is. There is a connect keyword unicode_results that forces all retrieved strings to be converted to Unicode. This is sort-of a stopgap Unicode feature until the 3.x version is released. If you really need Unicode errors, I guess I could add a unicode_errors keyword that would force errors to be returned in Unicode. Is that something you are interested in? (Also note that I can't promise it will work -- I'm using the Python C interface and until I try it I'm not entirely sure passing Unicode values to the constructor will work. I think so, though.) |