在 wsgi 中导入 python 模块时出现 500 内部服务器错误
我有一个 Python 脚本,它使用 PEST wsgi 库异步执行函数。但是,当我尝试导入另一个模块时,只会导致 500 错误。
我尝试引用它的方式是:
from foo import *
from foo import Foo
其中 foo 是一个文件 .py,其中我有我想要引用的对象。
尝试通过 Chrome 的 Inspect Element Control 监控调用,但找不到任何东西。
还尝试使用 Apache 的错误日志进行调试,但没有任何结果。
任何提示表示赞赏。
更新: 我尝试了以下方法,但导致了相同的 500 错误:
--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,通过插入上面的 WSGIPythonPath
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
Apache 的 500 错误只是告诉您 Python 脚本返回了错误。我的猜测是,在 Apache 环境中,Python 找不到该模块。尝试使用一个简单的脚本来打印 sys.path 并确保其中包含您期望的目录。
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.在应用程序conf文件中的任何其他别名或目录之前添加
确实会产生影响。
问题解决了!
Adding
before any other alias or directory in the application conf file really makes the difference.
Problem solved!
也许您应该对 cgi 脚本使用此模式来将错误获取到 html 表单:
Maybe you should use this pattern for cgi scripts to get errors to html form:
如果异常传播回 mod_wsgi,则应将详细信息记录到相应的 Apache 错误日志中。如果不是,则可能是您正在使用的 WSGI 框架/工具包正在捕获异常并返回通用 HTTP 500 响应页面。如果是这种情况,您可能需要在正在使用的 WSGI 框架/工具包中启用调试选项。
或者,问题不在于 WSGI 脚本文件/应用程序,而在于 Apache 配置,在这种情况下,您不会寻找 Python 异常/回溯。因此,您需要更仔细地查看 Apache 错误日志文件,查找任何错误并提供其内容。
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.