pypyodbc过去曾为我工作过,但由于某种原因,它不起作用。我在~/.odbc.in i中定义了这个

[as400]
Description             = IBM i Access ODBC Driver
Driver                  = IBM i Access ODBC Driver
System                  = mysystem
UserID                  = myuser
Password                = mypass
Naming                  = 0
DefaultLibraries        = QGPL
Database                =
ConnectionType          = 0
CommitMode              = 2
ExtendedDynamic         = 1
DefaultPkgLibrary       = QGPL
DefaultPackage          = A/DEFAULT(IBM),2,0,1,0,512
AllowDataCompression    = 1
MaxFieldLength          = 32
BlockFetch              = 1
BlockSizeKB             = 128
ExtendedColInfo         = 0
LibraryView             = ENU
AllowUnsupportedChar    = 0
ForceTranslation        = 0
Trace                   = 0

而且可以很好地与$ isql as400连接。
但是,使用以下程序:
import pypyodbc

conn = pypyodbc.connect("Driver={as400};System=mysystem;Uid=myuser;Pwd=mypass;")

我得到这个错误:
Traceback (most recent call last):
  File "dbtest.py", line 3, in <module>
    conn = pypyodbc.connect("Driver={as400};System=mysystem;Uid=myuser;Pwd=mypass;")
  File "/home/wwerner/.virtualenvs/devtools/lib/python3.4/site-packages/pypyodbc.py", line 2435, in __init__
    self.connect(connectString, autocommit, ansi, timeout, unicode_results, readonly)
  File "/home/wwerner/.virtualenvs/devtools/lib/python3.4/site-packages/pypyodbc.py", line 2484, in connect
    check_success(self, ret)
  File "/home/wwerner/.virtualenvs/devtools/lib/python3.4/site-packages/pypyodbc.py", line 988, in check_success
    ctrl_err(SQL_HANDLE_DBC, ODBC_obj.dbc_h, ret, ODBC_obj.ansi)
  File "/home/wwerner/.virtualenvs/devtools/lib/python3.4/site-packages/pypyodbc.py", line 964, in ctrl_err
    raise Error(state,err_text)
pypyodbc.Error: ('IM002', '[IM002] [unixODBC][Driver Manager]Data source name not found, and no default driver specified')

我试着在pypyodbc源代码中寻找镜像isql -v能力的方法,但是VERBOSE = True不是。我还发现了一个bug,很明显它只会发送第一封信,我想也许我有这个问题,但我不知道从哪里可以找到它。
我怎样才能让它重新工作?

最佳答案

python脚本失败,因为'as400'是您创建的odbc dsn的名称,所以您需要在连接字符串中使用DSN=as400而不是Driver={as400}

09-20 10:34