Problems getting Python scripts to run on server

Y

Yansky

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?
 
I

I V

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

Note that you don't get a 404 error _from the web server_ - you get it
from wordpress (or at least, I do when I look at your page). So what I
think is happening is that either the server, or wordpress, doesn't see a
file at the URL "/cgi-bin/wp.py", and so it thinks your are trying to
access a wordpress post, and http://forboden.com/cgi-bin/wp.py is getting
translated to http://forboden.com/index.php/cgi-bin/wp.py .

I suspect the problem is in the rewrite rules in the .htaccess in your
root directory. My wordpress installation has these rewrite rules:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

Which, as I understand it mean "not a file" and "not a directory"
respectively. If your cgi-bin is not in your document root, presumably
cgi-bin/wp.py will indeed show up as not being a file or directory. I'm
no mod_rewrite wizard, but looking at the docs[1], maybe you could
replace those two lines above with:

RewriteCond %{REQUEST_URI} !-U

(thought the docs say this "can impact your server's performance!") I'm
just guessing at the cause of your problem, but I hope this helps.

[1] http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html
 
7

7stud

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.
 
7

7stud

I just wanted to point out that the <Directory> tag below would go in
the httpd.conf file(a config file for apache), which you apparently do
not have access to. I was suggesting that you check with your host to
make sure they have the right AllowOverride line.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,040
Latest member
papereejit

Latest Threads

Top