| Issue 108: | Unicode paths gives UnicodeEncodeError | |
| 3 people starred this issue and may be notified of changes. | Back to list |
What steps will reproduce the problem?
Run a program similar to this:
# encoding: utf-8
import pyodbc
MDB_CONN_STRING = u'DRIVER={{Microsoft Access Driver (*.mdb)}};DBQ={0};'
def test(path):
cnxn = pyodbc.connect(MDB_CONN_STRING.format(path))
cursor = cnxn.cursor()
cursor.execute('select * from DB')
for row in cursor:
print '.'
test(ur'C:\path\without\unicode\chars.mdb')
test(ur'C:\path\with\unicode\chars\åøæ.mdb')
What is the expected output? What do you see instead?
An UnicodeEncodeError is throw in the second invocation of test in the for loop. If you comment out the loop no exception is thrown.
What version of the product are you using? On what operating system?
pyodbc 2.1.7 on Windows XP with Python 2.6.2.
Aug 26, 2010
Project Member
#1
mkleehammer
Status:
Investigating
Nov 21, 2010
(No comment was entered for this change.)
Status:
Hold
Jul 18, 2011
Hi
I had the same issue if need a unicode string to connect:
Systems tested: Windows 7, windows XP and Windows2000 sp4
Python version: 2.7
pyodbc version: 2.1.8
1. Created two copies of 1 database.
The first uses a pure ascii password
the second uses a passwor wich contains a unicode character "yyy\xe9yyyy"
2. Create ODBC datasources for both databases an test they works properly
3. Retrive the DSN info from the system registry using a python script.
4. link the DSN info creating proper DSN strings DSN1 and DSN2
the only difference is DSN2 contains the character \xe9 (in the registered password)
DSN1 = "DSN=Db1CopyDSNName;PWD=Db1password"
DSN2 = u"DSN=Db2CopyDSNName;PWD=Db2password" #so it contains 1 unicode char.
5. create connections:
>>> cnn1 = pyodbc.connect(DSN1) #SUCCESS
>>> cnn2 = pyodbc.connect(DSN2) #SYSTEM EXCEPTION
6. The exception as was printed by IDLE:
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
cnn = pyodbc.connect('DSN=adsntodb1PwdUtf;PWD=Némesis')
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe9 in position 25: ordinal not in range(128)
SUGESTION: I've got the same exception when reading from databases wich contains utf strings and manipulate the outputs. I've solved it creating a simple script to ensure all the strings, I use, are unicode. I supouse the codec exception raises when pyodbc links the dsn to perform operations (perhaps before passig the info to your C libraries)
|