Problems getting Python scripts to run on server

7stud bbxx789_05ss at yahoo.com
Thu Jan 24 01:30:28 EST 2008


On Jan 23, 8:41 pm, Yansky <thegoodd... at gmail.com> wrote:
> Hi, I'm having a lot of problems getting any Python scripts to run on
> my website. I have put them in the cgi-bin directory and chmodded both
> the directory and files to 755. But when I try to access the script, I
> get a 404 error:http://forboden.com/cgi-bin/wp.py
>
> I also tried running them from another directory and giving the
> directory its own .htaccess file containing:
> Options +ExecCGI
> AddHandler cgi-script .py
>
> but again, they still wouldn't run.
>
> The odd thing is, its not that they don't run per se, but that I get a
> 404 error. When I tried the scripts in the other folder (the non cgi-
> bin folder), before I added a .htaccess file, I tried the scripts and
> sure enough it displayed the file source code. But when I added
> the .htaccess file, I got a 404 file not found error.
>
> I emailed my hosting company and they said:
> "Python is currently installed on the server and is running without
> any issues. The URL you have provided is not showing any errors on the
> server. I would advise checking over your scripting to ensure that the
> issue isn't there."
>
> Anyone have any ideas as to what's going wrong?

Here are some things you can try:

1) Maybe your server is setup so that your program file must have
a .cgi extension instead of being in a cgi-bin directory.

2) Does your program have a shebang line at the top, e.g.

#!/usr/bin/env python


3) "What you can put in <.htaccess> files is determined by the
AllowOverride directive."

e.g.

<Directory "/Library/Apache2/cgi-bin">
    AllowOverride FileInfo
    Options None
    Order allow,deny
    Allow from all
</Directory>

"Note: you must have "AllowOverride Options" in effect to permit the
use of the "Options" directive in .htaccess files."

So, in the above example the line starting with AllowOverride would
need to have "Options" instead of FileInfo(or maybe in addition to?).

More info from http://httpd.apache.org/docs/2.0/howto/htaccess.html :
-------
Finally, you may wish to use a .htaccess file to permit the execution
of CGI programs in a particular directory. This may be implemented
with the following configuration:

Options +ExecCGI
AddHandler cgi-script cgi pl

Alternately, if you wish to have all files in the given directory be
considered to be CGI programs, this may be done with the following
configuration:

Options +ExecCGI
SetHandler cgi-script

Note that AllowOverride Options and AllowOverride FileInfo must both
be in effect for these directives to have any effect.

Please see the CGI tutorial for a more complete discussion of CGI
programming and configuration.
-----

According to that passage, you should have the extension 'py' not
'.py' in the AddHandler part.  I don't know if that makes a
difference.  Go to that web page and click the link to the CGI
tutorial, and maybe you can find some clues on how to configure your
directories with .htacesss files.



More information about the Python-list mailing list