I almost gave up when I took a nap and had a vision of what was happening. Over the last several days, I have been trying to get python scripts to run on my shared 1&1 hosting service.
Being shared was one thing, being 1and1 yet another. I want to share my plight and, ultimately, my success in getting a python script to run.
Most important to consider in your troubleshooting: If you're getting an "HTTP error 500 Internal Server Error", then this will probably help you!
I use Dreamweaver as my IDE (Integrated Development Environment); it is a great tool that provides a host of visual queues and nice file manipulation in one program.
Dreamweaver is set to use the default Windows CR/LF. So, when you upload your file via FTP and you have the Windows CR/LF setting enabled, all your files end up with CR/LF instead of the wanted /LF for Unix/Linux hosts.
What does it matter? Well, your python scrips WILL NOT execute if you have CR/LF's in your script! Period! A couple of options to correct this: The first and most obvious is to simply change your settings in Dreamweaver or whatever program you use to write your scripts, to use Unix LF's rather than Windows/DOS CR/LF's (carriage return/line feed). The second option is to use a simple Perl command to strip out CR/LF's (which show up as /r) from your script.
The perl command is: (remember, case is important on a Unix/Linux system)
perl -i -pe's/\r$//;' filename
...say from your ssh command prompt. If you have 1&1, you can use Putty with your FTP username and password to access it.
Permissions are a big thing. To make your script executable, you will need to issue the following command in your ssh session:
chmod 755 filename
Then, just to make sure the script will work and debug errors, type the name of the script to execute it from the command prompt; for example:
test.py
or...
./test.py
Ensure you are either in the directory containing the file or specify the files path to execute it from a different directory, i.e. /cgi-bin/test.py or ./cgi-bin/test.py
Another big deal is putting in the hashbang "#!" (the first line of your script: #!/usr/bin/python) for your "interpreter". The interpreter is your python executable. Maybe located at /usr/bin/python. I found that this path works fine, as it is in the Unix path, but does drive you to use python 2.4.4 (as of the writing of this post). They also have python 2.5 installed. If you wish to install a later version, i.e. 2.6.2, then you're on your own, though it is pretty easy; I may address that in another post.
Resources
| < Prev | Next > |
|---|



Web & Internet 



