python - How to connect to access (.mdb) database with pyodbc using latin-1 filename -
i use code connect access (.mdb) database:
# -*- coding: latin-1 -*- filemdb = 'c:\\python27\\optimisateurlievre\\final\\archives_previsionsesp_août_2013.mdb' param = "driver={microsoft access driver (*.mdb)};dbq={%s};pwd={pw}" % filemdb con = odbc.connect(param)
i following error:
pyodbc.error: ('hy000', '[hy000] [microsoft][pilote odbc microsoft access] filename incorrect. (-1044) (sqldriverconnect); [hy000] [microsoft][pilote odbc microsoft access] filename incorrect. (-1044)')
the problem seems come database filename û caracter. understanding of string , unicode, filemdb string encoded in latin-1. since, computer runs latin-1 encoding don't understand why filename incorrect.
i work windows xp , python 2.7.
thank help!
it appears pyodbc tries convert connection string 'ascii'
, characters above 0x7f invalid:
con = pyodbc.connect(param)
unicodedecodeerror: 'ascii' codec can't decode byte 0xfb in position 84: ordinal not in range(128)
however, able work using pypyodbc:
# -*- coding: cp1252 -*- import pypyodbc filemdb = r'c:\__tmp\test\archives_previsionsesp_août_2013.mdb' param = "driver={microsoft access driver (*.mdb)};dbq=" + filemdb con = pypyodbc.connect(param) print 'connection established.'
Comments
Post a Comment