简体   繁体   中英

CGI not executing python - 500 internal server error

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?

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.

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM