问题
I've got a Python script that is executing functions asynchronously by using PEST wsgi library. However, when I try to import another module it simply results in a 500 error.
The way I try to reference it is:
from foo import *
from foo import Foo
where foo is a file .py in which I have the object that I want to reference to.
Tried to monitor the calls through Chrome's Inspect Element Control but couldn't find a thing.
Also tried to debug using Apache's error log, but nothing there.
Any hints appreciated.
Update: I've tried the following which resulted in the same 500 error:
--make use of
import site
and
site.addsitedir("path/to/my/py/files/folder")
--modify the Apache2 httpd.conf file by inserting the following:
WSGIPythonPath /path/to/my/py/files/folder
--modify the application conf file in /etc/apache2/sites-available/myapp.conf, by inserting the above WSGIPythonPath
回答1:
Apache's 500 error just tells you that the Python script is returning an error. My guess is that in the Apache environment, Python can't find that module. Try a simple script that prints sys.path
and makes sure it has the directories in it you expect.
回答2:
Adding
WSGIPythonPath /path/to/my/py/files/folder
before any other alias or directory in the application conf file really makes the difference. Problem solved!
回答3:
Maybe you should use this pattern for cgi scripts to get errors to html form:
import cgi
import cgitb; cgitb.enable() # for troubleshooting
import traceback
# code here
except:
tb = traceback.format_exception(sys.exc_type, sys.exc_value, sys.exc_traceback)
tb = ''.join(tb)
print '<pre>%s</pre></body></html>' % tb
回答4:
If an exception propagates back up to mod_wsgi then the details should be logged to appropriate Apache error log. If it isn't, then it may be that the WSGI framework/toolkit you are using is capturing the exception and returning a generic HTTP 500 response page. If that is the case, you may need to enable debug option in that WSGI framework/toolkit being used.
Alternatively, the problem isn't with the WSGI script file/application but with Apache configuration in which case you wouldn't be looking for a Python exception/traceback. You thus need to look more carefully at the Apache error log files and look for any error at all and provide what it says.
来源:https://stackoverflow.com/questions/5284362/500-internal-server-error-when-importing-a-python-module-in-wsgi