It's also possible to simply put the driver on the driver path. Isn't this configuration of the driver too cumbersome

driver = '/usr/irisodbc/bin/libirisodbc35.so'
server = ''
database = ''
username = ''
password = ''
port = ''


cnxn = pyodbc.connect(driver=driver, server=server,port='1972', database=database, uid=username, pwd=password,charset='UTF-8')
###ensure it reads strings correctly.
cnxn.setdecoding(pyodbc.SQL_CHAR, encoding='utf8')
cnxn.setdecoding(pyodbc.SQL_WCHAR, encoding='utf8')
cnxn.setencoding(encoding='utf8')
cursor = cnxn.cursor()
cursor.execute("select top 10 * from xx.xx")
row = cursor.fetchone()
while row:
    print(row)
    row = cursor.fetchone()

cnxn.close()

这个比odbc连接坑少,我使用odbc在linux中查到的字段都是空字符串,如下:

python3 /home/code/httpTest2.py
('', '', '', '', None, '')
('', '', '', '', None, '')
('', '', '', '', None, '')
('', '', '', '', None, '')
('', '', '', '', None, '')
('', '', '', '', None, '')
('', '', '', '', None, '')
('', '', '', '', None, '')
('', '', '', '', None, '')
('', '', '', '', None, '')