Skip to main content
 首页 » 编程设计

python 粘贴不显示错误跟踪

2025年05月04日8hnrainll

我已经使用 Passenger WSGI 设置了一个托管在 Dreamhost 上的 Django 项目 according to their wiki instructions并遇到内部错误弹出和 mod_wsgi 崩溃的问题。

我通过 following their instructions 安装了 Python Paste获取网页中显示的综合日志,但它不起作用。 IE:每当我有内部错误时,我仍然会在浏览器中看到没有任何其他信息的 django 的“内部错误”页面。

当我通过删除“def testapplication”前面的“test”来测试 paste 的安装时,效果很好。但是每当我遇到内部错误时,我仍然无法获得包含完整错误信息的 paste 输出。相反,我得到了相同的神秘内部错误页面,但没有任何信息。

根据他们的wiki,我的配置是正确的:

我的 passenger_wsgi.py 文件:

import os, sys 
import django.core.handlers.wsgi 
 
INTERP = os.path.join(os.environ['HOME'], 'env', 'bin', 'python') 
if sys.executable != INTERP: 
    os.execl(INTERP, INTERP, *sys.argv) 
 
os.environ['DJANGO_SETTINGS_MODULE'] = "abc.settings" 
 
sys.path.append(os.getcwd()) 
sys.path.append(os.path.join(os.getcwd(), 'abc')) 
log = file('/home/abcadmin/passengerwsgi.log', 'a') 
print >>log, "Running %s" % (sys.executable) 
 
application = django.core.handlers.wsgi.WSGIHandler() 
 
from paste.exceptions.errormiddleware import ErrorMiddleware 
sys.stdout = sys.stderr 
 
# remove the "test" below to test paste 
def testapplication(environ, start_response): 
    status = '200 OK' 
    output = 'Hello World! Running Python version ' + sys.version + '\n\n' 
    response_headers = [('Content-type', 'text/plain'), 
               ('Content-Length', str(len(output)))] 
    # to test paste's error catching prowess, uncomment the following line 
    # while this function is the "application" 
    raise("error") 
    start_response(status, response_headers)     
    return [output] 
 
application = ErrorMiddleware(application, debug=True) 

我的 Web 服务器错误日志 (error.log) 是空的,而我的访问日志 (access.log) 充满了如下消息(最新行 - 使用虚假链接编辑)。某处发生了日志记录,因为 access.log 正在记录一些东西,但错误没有显示在任何地方 - 除了那个神秘的“内部错误”页面。

46.246.117.3 - - [21/Feb/2012:00:27:04 -0800] "GET /admin/ HTTP/1.1" 200 2326 "http://abc.acme.com/admin/userProfile/profile/16/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:10.0.2) Gecko/20100101 Firefox/10.0.2" 

Django 项目在我的开发环境中运行良好,但是当它在服务器上运行 Passenger WSGI 时出现某种服务器问题 - 我安装了 Paste 来尝试调试这些错误。当我的安装遇到任何类型的非 Django 错误时,我会收到神秘的“内部错误”消息。

请您参考如下方法:

如果您在某处遇到编译器错误,它可能甚至不会到达它知道您想使用粘贴错误处理程序的地步。查看您的错误日志。