Problems getting Python scripts to run on server

Discussion in 'Python' started by Yansky, Jan 24, 2008.

  1. Yansky

    Yansky Guest

    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?
    Yansky, Jan 24, 2008
    #1
    1. Advertising

  2. Yansky

    I V Guest

    On Wed, 23 Jan 2008 19:41:17 -0800, Yansky 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


    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
    I V, Jan 24, 2008
    #2
    1. Advertising

  3. Yansky

    7stud Guest

    On Jan 23, 8:41 pm, Yansky <> 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.
    7stud, Jan 24, 2008
    #3
  4. Yansky

    7stud Guest

    On Jan 23, 11:30 pm, 7stud <> wrote:

    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.

    >
    > 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 fromhttp://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.
    7stud, Jan 24, 2008
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Calvin Cheng
    Replies:
    1
    Views:
    366
    kretik
    Jun 19, 2008
  2. Cédric Lucantis
    Replies:
    0
    Views:
    712
    Cédric Lucantis
    Jun 19, 2008
  3. Jason Tishler
    Replies:
    0
    Views:
    1,094
    Jason Tishler
    Jun 19, 2008
  4. davidj411
    Replies:
    0
    Views:
    481
    davidj411
    Jun 27, 2008
  5. Replies:
    13
    Views:
    514
    Anno Siegel
    Sep 10, 2007
Loading...

Share This Page