Importing pyodbc results as Internal server error

2019-08-23 09:07发布

问题:

Executing the cmd as c:\>pip install pyodbc
"pyodbc.cp36-win32.pyd" file will be created

 Collecting pyodbc   Using cached
 pyodbc-4.0.21-cp36-cp36m-win32.whl Installing collected packages:
 pyodbc Successfully installed pyodbc-4.0.21


When I try to run in Apache24 Server the below code results in Internal Server Error

import pyodbc 
cnxn = pyodbc.connect("Driver={ODBC Driver 13 for SQL Server};"
                      "Server=DESKTOP;"
                      "Database=demo2017;"
                      "Trusted_Connection=yes;")

cursor = cnxn.cursor()
cursor.execute('SELECT * FROM Table')

for row in cursor:
    print('row = %r' % (row,)) 

Running in python shell as
C:\Apache24\htdocs>python mssql_odbc.py
Results will be displayed fine. But not at apache http server.

In httpd.conf file:

 LoadModule pyodbc_module "c:/users/desktop/appdata/local/programs/python/python36-32/lib/site-packages/pyodbc.cp36-win32.pyd"

Results

 httpd: Syntax error on line 571 of C:/Apache24/conf/httpd.conf: Can't
 locate API module structure `pyodbc_module' in file
 C:/Users/Desktop/AppData/Local/Programs/Python/Python36-32/Lib/site-packages/pyodbc.cp36-win32.pyd:
 No error

So are there any modules or code that should be imported/modified?

回答1:

In Apache 500 Internal Error Solved. Because of importing pypyodbc instead of import pyodbc.

In python shell I was able to connect successfully retrive the results in python shell as well as in Database.