通过添加一个语句,导入pyodbc会导致Apache HTTP Server中出现内部服务器错误

时间:2017-12-01 06:43:05

标签: python apache pyodbc django-pyodbc django-pyodbc-azure

在Apache Server中运行普通的旧的python文件。我用这种方式编码

index.html

<form action="/cgi-bin/hello_get.py" method="post">
First Name: <input type="text" name="first_name">  <br />

Last Name: <input type="text" name="last_name" />
<input type="submit" value="Submit" />
</form>

hello_get.py

#!C:/Users/Desktop/AppData/Local/Programs/Python/Python36-32/python

# Import modules for CGI handling
import cgi, cgitb
import pyodbc

# Create instance of FieldStorage
form = cgi.FieldStorage()

# Get data from fields
first_name = form.getvalue('first_name')
last_name  = form.getvalue('last_name')

print("Content-Type:text/html\r\n\r\n")
print("<html>")
print("<head>")
print("<title>Hello - Second CGI Program</title>")
print("</head>")
print("<body>")
print("<h2>Hello %s %s</h2>" % (first_name, last_name))
print("</body>")
print("</html>")

我试过在python shell中运行。它完美地工作了

同样在httpd.conf文件中:

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

结果

 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

那么我如何在.py文件中导入pyodbc 以及如何在Apache HTTP服务器中加载pyodbc模块

正如@FlipperPA所说,在此链接中加载mod_wsgi模块Click Here

C:\>pip install mod_wsgi-4.5.22+ap24vc9-cp27-cp27m-win32.whl

C:\Windows\system32>pip install htmlpy
Collecting htmlpy
  Downloading htmlPy-2.0.3.tar.gz
Installing collected packages: htmlpy
  Running setup.py install for htmlpy ... done
Successfully installed htmlpy-2.0.3

同样在httpd.conf文件中:

LoadFile "c:/users/desktop/appdata/local/programs/python/python36-32/python36.dll"
LoadModule wsgi_module "c:/users/desktop/appdata/local/programs/python/python36-32/lib/site-packages/mod_wsgi/server/mod_wsgi.cp36-win32.pyd"
LoadModule pyodbc_module "c:/users/desktop/appdata/local/programs/python/python36-32/lib/site-packages/pyodbc.cp36-win32.pyd"
WSGIPythonHome "c:/users/vitriv-desktop/appdata/local/programs/python/python36-32"

这是test_wsgi.py

#!C:/Users/AppData/Local/Programs/Python/Python36-32/python

import os
import sys
from wsgiref.simple_server import make_server


def hello_world_app(environ, start_response):
    status = '200 OK' # HTTP Status
    headers = [('Content-type', 'text/plain')] # HTTP Headers
    start_response(status, headers)
    pyver = '.'.join(map(str, tuple(sys.version_info)[:3]))
    return ["Hello World (from Python %s WSGI)" % pyver]


application = hello_world_app


if __name__ == '__main__':
    port = int(os.getenv('PORT', '8000'))
    srv = make_server('127.0.0.2', port, application)
    print("Serving...")
    srv.serve_forever()

输出:

  

Hello World(来自Python 2.7.14 WSGI)

但我现在不知道如何使用Web服务器网关接口? 请帮我解决上述两种方法中的至少一种方法

0 个答案:

没有答案