【问题标题】:Internal Server Error with Trac: "ModuleNotFoundError: No module named 'trac'"Trac 的内部服务器错误:“ModuleNotFoundError:没有名为 'trac' 的模块”
【发布时间】:2021-04-26 21:12:31
【问题描述】:

我正在新的 RHEL 8 服务器上安装 Trac,并且在 httpd 错误日志中收到内部服务器错误:

ModuleNotFoundError: No module named 'trac'

我尝试使用

查看审核日志
journal -xe | grep httpd 

(并且还为 tracapache 提供了 grep) - 以及那里显示的零错误信息。

httpd正常启动,没有错误。

Trac 被配置为使用 wsgi,它不是具有自己内置服务器的独立版本。 Apache HTTPD 应该是错误处理的。

这里是 httpd trac.conf 文件:

WSGIScriptAlias /trac /data/www/virtualhosts/trac/cgi-bin/trac.wsgi
 
<Location "/trac/login">
  AuthType Basic
  AuthName "Issue Tracker"
  AuthUserFile /data/www/virtualhosts/trac/conf/trac.htpasswd
  Require valid-user
</Location>
 
 
<Directory /data/www/virtualhosts/trac/cgi-bin>
    WSGIApplicationGroup %{GLOBAL}
    # For Apache 2.2
    <IfModule !mod_authz_core.c>
        Order deny,allow
        Allow from all
    </IfModule>
    # For Apache 2.4
    <IfModule mod_authz_core.c>
        Require all granted
    </IfModule>
</Directory>

和 trac.wsgi

import os
 
def application(environ, start_request):
    if not 'trac.env_parent_dir' in environ:
        environ.setdefault('trac.env_path', '/data/www/virtualhosts/trac')
    if 'PYTHON_EGG_CACHE' in environ:
        os.environ['PYTHON_EGG_CACHE'] = environ['PYTHON_EGG_CACHE']
    elif 'trac.env_path' in environ:
        os.environ['PYTHON_EGG_CACHE'] = \
            os.path.join(environ['trac.env_path'], '.egg-cache')
    elif 'trac.env_parent_dir' in environ:
        os.environ['PYTHON_EGG_CACHE'] = \
            os.path.join(environ['trac.env_parent_dir'], '.egg-cache')
    from trac.web.main import dispatch_request
    return dispatch_request(environ, start_request)

python版本

[user@box] # python --version
Python 2.7.17 

我不知道为什么我无法获得任何错误信息以显示在屏幕上或最好写入日志文件。这台服务器不是生产服务器,所以我现在可以在屏幕上显示一些东西。

非常感谢任何帮助

【问题讨论】:

  • 我会尝试运行 TracStandalone 来验证您的 Trac 安装。此外,请检查 trac.wsgi 的权限,并可能共享您的 Apache 站点文件内容。
  • trac.wsgi 应该是可执行的吗?目前 644
  • tracd 从命令行启动时没有错误,但我无法测试,因为端口 8080 在我的组织中的网络级别被阻止
  • 是的,trac.wsgi 需要被 Apache 执行。
  • 将 trac.wsgi 设置为可执行文件,重新启动 httpd 仍然得到 ModuleNotFoundError: No module named 'trac'

标签: apache error-handling httpd.conf internal-server-error trac


【解决方案1】:

问题可能在于cgi-bin 目录或其父目录之一的权限。

trac-admindeploy 命令会为你创建一个trac.wsgi,但你需要部署在你的环境目录之外,否则你会得到这个错误:

Error: Resources cannot be deployed to a target directory that is equal to or below the source directory '/Users/rjollos/Documents/Workspace/trac-dev/tracenvs/proj-1.4/htdocs'.

Please choose a different target directory and try again.

如果你的环境是/data/www/virtualhosts/trac,运行:

$ trac-admin /data/www/virtualhosts/trac deploy /data/www/virtualhosts/www

然后将您的虚拟主机文件指向/data/www/virtualhosts/www/cgi-bin/trac.wsgi

【讨论】:

  • 在上面申请并重启httpd之后继续去get[Mon May 03 17:59:34.043574 2021] [wsgi:error] [pid 250003:tid 139841006806784] [client IP:16389] ModuleNotFoundError: No module named 'trac'
  • 系统路径上的默认 Python 是 Python 3 而不是 Python 2?检查python --version
  • python --version Python 2.7.17
  • 问题出在 Python 路径上。另外我认为您的 trac.wsgi 需要在顶部使用#!/path/to/pythonwhich python 的输出是什么? Trac 安装在哪里? python -c import trac 成功了吗?
  • which python /usr/bin/python。 Trac 安装到/data/www/virtualhosts/trac/
猜你喜欢
  • 1970-01-01
  • 2020-07-30
  • 2022-01-13
  • 2020-01-01
  • 2019-03-09
  • 2019-10-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多