在 Apache Server 中运行普通学校的旧 python 文件。我是这样编码的
索引.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 模块单击此处
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 服务器网关接口?
请帮助我从上述两种方法中解决至少一种方法