CGI 不执行 python - 500 内部服务器错误

发布于 2024-10-10 15:28:56 字数 2256 浏览 0 评论 0原文

我有一些想要执行的 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

站点可用中的默认文件:

<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 文件只是打印一些应该出现在页面上的文本。 我应该怎么办? 谢谢

[编辑]:更新,与py文件中的错误有关 错误日志如下所示。

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'))

关于如何完成此类转换的任何提示?

I have a few python scripts that I'd like to execute and the following configuration:
Ubuntu 10.04, Apache2, Python 2.6, mod_python and mod_wsgi installed.

I've followed the instructions on the following sites:

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

The default file in 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>

I'm getting the 500 internal server error.
I've also changed the permissions of the files to 755

The py files simply prints some text that should appear on the page.
What should I do?
Thanks

[edit]: Update, it's related to bugs in the py file
error log shown below.

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'

It appears to be an error in converting from None to int, over here:

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

Any hint on how this can such a conversion be done?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

橪书 2024-10-17 15:28:56

如果 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)

If parms.getfirst('zoom') or parms.getfirst('zsize') return None, you are probably not providing these in your URL (? dunno what these parms are, just guessing). Define the behaviour you want when these are missing (will it mean a "0" zoom, or since you are multiplying, "1" makes more sense?).

Then create your own conversion function that knows how to translate a None to int (depending on your defined behaviour) and call it instead of int().

def convert(value):
   if value is None:
      return 0 # or 1, or whatever
   else:
      return int(value)
若水般的淡然安静女子 2024-10-17 15:28:56

您没有加载 wsgi 模块。

LoadModule wsgi_module modules/mod_wsgi.so

另外,您只需要安装 mod_wsgi 或 mod_python 。除非您有特定需要,否则两者都不会。

You're not loading the wsgi module.

LoadModule wsgi_module modules/mod_wsgi.so

Also, you need only mod_wsgi OR mod_python installed. Not both unless you have a specific need to do so.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文