简体   繁体   English

将Django Pyodbc应用程序转换为apache时,odbc连接错误

[英]odbc connection error when transitioning django pyodbc application to apache

I have tried the following fix: https://code.google.com/p/pyodbc/issues/detail?id=214 我尝试了以下修复程序: https : //code.google.com/p/pyodbc/issues/detail?id=214

and am still getting the same error. 并且仍然出现相同的错误。

Any idea as to how I can remedy this situation? 关于如何解决这种情况的任何想法?

here is a screenshot of the odbc dns listings 这是odbc dns列表的屏幕截图 在此处输入图片说明

Python code Python代码

import pyodbc
import datetime as dt
from broker.models import Customer, Usage, Invoice, Document


def import_customers(user_id,m_code):
    cnxn = pyodbc.connect('DSN=as400;PWD=*********;DBQ=PRODDTA')
    cursor = cnxn.cursor()

    # the VNDRCODE of LQPPNATSLC is equivalent to the VENDORNUM of the LQPPNATVND !!!
    # the VNDRCODE of LQPPNATVND is ACTUALLY the decriptive name of the broker
    cursor.execute("""select b.CUSTNBR,
                             b.CONAME,
                             b.LASTNAME,
                             b.FIRSTNAME,
                             b.MIDDLEINT,
                             b.STREET1,
                             b.STREET2,
                             b.CITY,
                             b.STATE,
                             b.ZIPCODE,
                             b.ZIPEXTN,
                             b.PHONENBR,
                             a.PCID,
                             c.VNDRCODE as VNAME,
                             d.STREET1,
                             d.CITY,
                             d.STATE,
                             d.ZIPCODE,
                             a.VNDRCODE 
                    from LQPPNATSLC a, LQPPCUSMST b, LQPPNATVND c, LQPPDELDIR d
                    where a.CUSTNBR = b.CUSTNBR and
                          a.CUSTNBR = d.CUSTNBR and
                          a.VNDRCODE = c.VENDORNUM and
                          b.CUSTSTAT in ( '','RE') and
                          a.VNDRCODE = ? 
                    order by b.CUSTNBR """,str(m_code))

    Customer.objects.filter(user_id=user_id).delete()
    row = cursor.fetchone()
    while row:      
        b = Customer( user_id = user_id,
                    customer_number = row.CUSTNBR,
                    company_name = row.CONAME,
                    last_name = row.LASTNAME,
                    first_name = row.FIRSTNAME,
                    middle_initial = row.MIDDLEINT,
                    street_address1 = row.STREET1,
                    street_address2 = row.STREET2,
                    city = row.CITY,
                    state = row.STATE,
                    zip = row.ZIPCODE,
                    zip_ext = row.ZIPEXTN,
                    phone = row.PHONENBR,                   
                    PCID = row.PCID,
                    broker_name = row.VNAME, # see note above
                    service_address1 = row.STREET1,
                    service_city = row.CITY,
                    service_state = row.STATE,
                    service_zip = row.ZIPCODE,
                    broker_code = row.VNDRCODE.strip()
                    )
        b.save()
        row = cursor.fetchone()

Error from apache errror.log 来自apache errror.log的错误

[Mon Aug 26 13:50:41 2013] [error]   File "C:\\Python27\\Lib\\site-packages\\django\\core\\handlers\\base.py", line 115, in get_response
[Mon Aug 26 13:50:41 2013] [error]     response = callback(request, *callback_args, **callback_kwargs)
[Mon Aug 26 13:50:41 2013] [error]   File "C:\\Python27\\Lib\\site-packages\\django\\contrib\\auth\\decorators.py", line 25, in _wrapped_view
[Mon Aug 26 13:50:41 2013] [error]     return view_func(request, *args, **kwargs)
[Mon Aug 26 13:50:41 2013] [error]   File "C:\\dev\\broker_portal\\broker\\views.py", line 57, in customer_list
[Mon Aug 26 13:50:41 2013] [error]     as400.import_customers(user_id,marketer_code)
[Mon Aug 26 13:50:41 2013] [error]   File "C:\\dev\\broker_portal\\broker\\as400.py", line 7, in import_customers
[Mon Aug 26 13:50:41 2013] [error]     cnxn = pyodbc.connect('DSN=as400;PWD=*********;DBQ=PRODDTA')
[Mon Aug 26 13:50:41 2013] [error] Error: ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (0) (SQLDriverConnect)')

Django debug error Django调试错误

Error at /broker/5/3/
('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (0) (SQLDriverConnect)')
Request Method: GET
Request URL:    http://djangodev.shipley.com/broker/5/3/
Django Version: 1.5.1
Exception Type: Error
Exception Value:    
('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (0) (SQLDriverConnect)')
Exception Location: C:\dev\broker_portal\broker\as400.py in import_customers, line 7
Python Executable:  C:\Apache2\bin\httpd.exe
Python Version: 2.7.5
Python Path:    
['C:\\dev\\broker_portal',
 'C:\\Python27',
 'C:\\Python27\\Lib\\site-packages',
 'C:\\Python27\\Scripts',
 'C:\\Apache2',
 'C:\\Windows\\system32\\python27.zip',
 'C:\\Python27\\Lib',
 'C:\\Python27\\DLLs',
 'C:\\Python27\\Lib\\lib-tk',
 'C:\\Apache2\\bin']
Server time:    Mon, 26 Aug 2013 13:50:41 -0400

meta data 元数据

wsgi.multiprocess   
False
HTTP_COOKIE 
'csrftoken=ukCmTMgFUDtnSBvbOWYexafiTa4FPmmV; sessionid=qnh4u7n6mishbc4ka1oofxfd2fhtiraw'
SERVER_PROTOCOL 
'HTTP/1.1'
SERVER_SOFTWARE 
'Apache/2.2.25 (Win64) mod_wsgi/3.5-BRANCH Python/2.7.5'
SCRIPT_NAME 
u''
mod_wsgi.enable_sendfile    
'0'
mod_wsgi.handler_script 
''
SERVER_SIGNATURE    
''
REQUEST_METHOD  
'GET'
PATH_INFO   
u'/broker/5/3/'
SystemRoot  
'C:\\Windows'
QUERY_STRING    
''
HTTP_USER_AGENT 
'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.57 Safari/537.36'
HTTP_CONNECTION 
'keep-alive'
HTTP_REFERER    
'http://djangodev.shipley.com/accounts/login/'
SERVER_NAME 
'djangodev.shipley.com'
REMOTE_ADDR 
'10.1.6.182'
mod_wsgi.request_handler    
'wsgi-script'
wsgi.url_scheme 
'http'
PATH_TRANSLATED 
'C:\\dev\\broker_portal\\broker_portal\\wsgi.py\\broker\\5\\3\\'
SERVER_PORT 
'80'
mod_wsgi.version    
(3, 5)
mod_wsgi.input_chunked  
'0'
SERVER_ADDR 
'10.1.4.161'
DOCUMENT_ROOT   
'C:/Apache2/htdocs'
mod_wsgi.process_group  
''
COMSPEC 
'C:\\Windows\\system32\\cmd.exe'
SCRIPT_FILENAME 
'C:/dev/broker_portal/broker_portal/wsgi.py'
SERVER_ADMIN    
'admin@example.com'
wsgi.input  
<mod_wsgi.Input object at 0x00000000044BD9F0>
HTTP_HOST   
'djangodev.shipley.com'
mod_wsgi.callable_object    
'application'
wsgi.multithread    
True
PATHEXT 
'.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC'
HTTP_CACHE_CONTROL  
'max-age=0'
REQUEST_URI 
'/broker/5/3/'
HTTP_ACCEPT 
'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'
WINDIR  
'C:\\Windows'
wsgi.version    
(1, 0)
GATEWAY_INTERFACE   
'CGI/1.1'
wsgi.run_once   
False
wsgi.errors 
<mod_wsgi.Log object at 0x00000000044924F0>
REMOTE_PORT 
'50753'
HTTP_ACCEPT_LANGUAGE    
'en-US,en;q=0.8'
mod_wsgi.application_group  
'DjangoDev.shipley.com|'
mod_wsgi.script_reloading   
'1'
wsgi.file_wrapper   
''
CSRF_COOKIE 
u'ukCmTMgFUDtnSBvbOWYexafiTa4FPmmV'
HTTP_ACCEPT_ENCODING    
'gzip,deflate,sdch'

httpd.conf modifications httpd.conf修改

AliasMatch ^/([^/]*\.css) /dev/broker_portal/broker/css/$1

# Alias /media/ /path/to/mysite.com/media/
Alias /static/ /dev/broker_portal/broker/static/

<Directory  /dev/broker_portal/broker/static>
Order deny,allow
Allow from all
</Directory>

#<Directory /path/to/mysite.com/media>
#Order deny,allow
#Allow from all
#</Directory>

WSGIScriptAlias / /dev/broker_portal/broker_portal/wsgi.py
WSGIPythonPath /dev/broker_portal

<Directory /dev/broker_portal/broker_portal>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>
#
# Dynamic Shared Object (DSO) Support
#
# To be able to use the functionality of a module which was built as a DSO you
# have to place corresponding `LoadModule' lines at this location so the
# directives contained in it are actually available _before_ they are used.
# Statically compiled modules (those listed by `httpd -l') do not need
# to be loaded here.
#
# Example:
# LoadModule foo_module modules/mod_foo.so

LoadModule wsgi_module modules/mod_wsgi.so

An alternative is to embed the connection string, instead of maintaining a DSN outside of your code. 一种替代方法是嵌入连接字符串,而不是在代码外维护DSN。 You'll need to work with the connection string syntax, but here's something to get started (I'm using a mix a string and keywords as defined in the pyodbc.connect docs): 您将需要使用连接字符串语法,但是这里有一些入门(我正在使用pyodbc.connect文档中定义的字符串和关键字的混合):

cnxn = pyodbc.connect('system=<insert system name';dbq='PRODDTA',
                      driver='{iSeries Access ODBC Driver}',
                      uid='<insert user name>', pwd='<insert password>')

I find this method makes the inevitable code migration easier. 我发现这种方法使不可避免的代码迁移更加容易。

您将需要将DSN设置为系统DSN,因为Apache用户是“系统”用户,并且将查看系统DSN而不是用户DSN。

This connection string for pyodbc, work for me: 这个pyodbc的连接字符串对我有用:

conexion_str = 'SYSTEM=%s;db2:DSN=%s;UID=%s;PWD=%s;DRIVER=%s;' % (self._SYSTEM, self._DSN, self._UID, self._PWD, self._DRIVER)
cnn = pyodbc.connect(conexion_str)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM