Need help with first program to connect to mysql database via apache and python.

Steve Holden steve at holdenweb.com
Wed Feb 6 21:41:59 EST 2008


pythonbrian wrote:
> I am just learning python and I am trying to create a simple
> connection to a mysql table via Python and Apache, using a Python
> program
> Unfortunately I keep getting an internal server error (50), when I
> bring it up in my browser ... information attached.
> Any help would be appreciated ...
> Thx, brianmarsh at yahoo.com
> 
> Information #1
> error in /var/log/apache2/error.log
> 
> [Wed Feb 06 20:04:31 2008] [error] [client 127.0.0.1] (2)No such file
> or directory: exec of '/var/www/cgi-bin/fig17_27.py' failed
> 
> [Wed Feb 06 20:04:31 2008] [error] [client 127.0.0.1] Premature end of
> script headers: fig17_27.py
> 
> 
> -----------------------------------------------------------------------
> Information #2
> directory information
> 
> brianmarsh at ubuntu:/var/log/apache2$ cd /var/www/cgi-bin
> 
> brianmarsh at ubuntu:/var/www/cgi-bin$ ls -al
> 
> total 24
> 
> drwxr-xr-x 2 root root 4096 2008-02-06 15:03 .
> 
> drwxr-xr-x 4 root root 4096 2008-02-02 20:53 ..
> 
> -rwxr-xr-x 1 root root 1569 2008-02-02 21:02 fig06_03.py
> 
> -rwxr-xr-x 1 root root 2067 2008-02-02 21:05 fig06_05.py
> 
> -rwxr-xr-x 1 root root 2031 2008-02-02 21:19 fig06_06.py
> 
> -rwxr-xr-x 1 root root 3489 2008-02-06 15:03 fig17_27.py
> 
> 
> -----------------------------------------------------------------------------------------
> Web Error
> 
> http://localhost/cgi-bin/fig17_27.py
> 
> Internal Server Error
> The server encountered an internal error or misconfiguration and was
> unable to complete your request.
> Please contact the server administrator, webmaster at localhost and
> inform them of the time the error occurred, and anything you might
> have done that may have caused the error.
> More information about this error may be available in the server error
> log.
> 
> Apache/2.2.4 (Ubuntu) mod_python/3.3.1 Python/2.5.1 PHP/
> 5.2.3-1ubuntu6.3 Server at localhost Port 80
> 
> ------------------------------------------------------------------------------
> Program File
brianmarsh at ubuntu:/var/www/cgi-bin$ cat fig17_27.py


#!/usr/local/bin/python


[...]

I've snipped the code, because the error message indicates it isn't 
being executed: your problem is more fundamental than a Python error.

I take it you do have an executable /usr/local/bin/python?

One thing that can trip you up is if you have carriage returns in tour 
script: then Apache fails to find the program from the shebang line 
because it takes the DR before the LF as part of the filename.

regards
  Steve
-- 
Steve Holden        +1 571 484 6266   +1 800 494 3119
Holden Web LLC              http://www.holdenweb.com/




More information about the Python-list mailing list