【问题标题】:CGI not executing python - 500 internal server errorCGI 不执行 python - 500 内部服务器错误
【发布时间】:2011-01-05 15:19:12
【问题描述】:

我有一些我想执行的 python 脚本和以下配置: 安装了 Ubuntu 10.04、Apache2、Python 2.6、mod_python 和 mod_wsgi。

我已按照以下网站上的说明进行操作:

http://bytes.com/topic/python/answers/474462-apache-python-ubuntu

http://apache.active-venture.com/cgi-configure.html

http://modpython.org/live/current/doc-html/inst-testing.html

http://code.google.com/p/modwsgi/wiki/QuickInstallationGuide

http://wiki.apache.org/httpd/DistrosDefaultLayout

sites-available 中的默认文件:

<VirtualHost *:80>
    ServerAdmin webmaster@localhost

    DocumentRoot /var/www
    <Directory />
            Options FollowSymLinks
            AllowOverride None
    </Directory>

    <Directory /var/www/>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride None
            Order allow,deny
            allow from all
    </Directory>

    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory "/usr/lib/cgi-bin">
            AddHandler mod_python .py
            AddHandler cgi-script .cgi py
            AllowOverride None
            Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
            Order allow,deny
            Allow from all
    </Directory>

我收到 500 内部服务器错误。 我还将文件的权限更改为 755

py 文件只是打印一些应该出现在页面上的文本。 我该怎么办? 谢谢

[edit]:更新,和py文件的bug有关 错误日志如下所示。

Traceback (most recent call last):
  File "/usr/lib/cgi-bin/amissa2.py", line 80, in <module>
    zoom_factor = int(parms.getfirst('zoom')) * int(parms.getfirst('zsize'))
TypeError: int() argument must be a string or a number, not 'NoneType'

从 None 转换为 int 似乎是一个错误,在这里:

zoom_factor = int(parms.getfirst('zoom')) * int(parms.getfirst('zsize'))

关于如何进行这种转换的任何提示?

【问题讨论】:

  • 更多的是系统管理员问题。检查您的日志。如果他们没有告诉您足够多的信息,请增加详细程度。
  • 您能否提供更多来自 Apache 错误日志的信息?尝试设置LogLevel debug。

标签: python apache2 cgi cgi-bin


【解决方案1】:

如果 parms.getfirst('zoom') 或 parms.getfirst('zsize') 返回 None,您可能没有在 URL 中提供这些(?不知道这些 parms 是什么,只是猜测)。定义当这些缺失时您想要的行为(这是否意味着“0”缩放,或者由于您正在相乘,“1”更有意义?)。

然后创建您自己的转换函数,该函数知道如何将 None 转换为 int(取决于您定义的行为)并调用它而不是 int()。

def convert(value):
   if value is None:
      return 0 # or 1, or whatever
   else:
      return int(value)

【讨论】:

    【解决方案2】:

    你没有加载 wsgi 模块。

    LoadModule wsgi_module modules/mod_wsgi.so
    

    另外,您只需要安装 mod_wsgi 或 mod_python。除非您有特殊需要,否则不能两者兼有。

    【讨论】:

      猜你喜欢
      • 2011-10-09
      • 2016-04-24
      • 2016-12-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多