2

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

[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不是这样。我还发现了一个错误,显然它过去只是发送第一封信,我想也许不知何故我遇到了这个问题,但我不知道在哪里可以找到它。

我怎样才能让它再次工作?

4

1 回答 1

0

您的 Python 脚本失败,因为“as400”是您创建的 ODBC DSN的名称,因此您需要在连接字符串中使用DSN=as400而不是。Driver={as400}

于 2014-11-05T16:59:48.617 回答