By adding one statement import pyodbc causes Internal Server Error in Apache HTTP Server

女生的网名这么多〃 提交于 2019-12-31 04:27:12

问题


To run the normal school old python file in Apache Server. I had coded this way

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>")

I have tried to run in python shell. It perfectly works

Also 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 How do I need to import pyodbc in .py file as well as how to load pyodbc module in Apache HTTP server?

As @FlipperPA said to load mod_wsgi module in this link 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

Also in httpd.conf file:

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"

This is 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()

Output:

Hello World (from Python 2.7.14 WSGI)

But I'm not aware how to use Web Server Gateway Interface now?
Kindly help me to resolve atleast one method from the above two methods

来源:https://stackoverflow.com/questions/47587961/by-adding-one-statement-import-pyodbc-causes-internal-server-error-in-apache-htt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!