Python


#1

What do i have to do so i can use python on my web page?
I get an error when i try to use

http://nothingparticular.net/test.py

http://nothingparticular.net


#2

There’s nothing special required. You should look in your error.log file to see if there’s more info. Also, try running the Python program from the command line.


#3

Ive get this error:
Premature end of script headers: /home/memix/nothingparticular.net/test.py

http://nothingparticular.net


#4

Where did you create the script? On a PC and then uploaded it? Sometimes when I’ve done that and had the same errors I log in to the server via SSH. Open the file in Pico and add a single space and save and close the file. Open and remove the space if you need.
Then set the files permissions, cross all known digits and hope for the best.

If you get the same errors you may have made a mistake of some sort.


N[color=#6600CC]or[/color]m

Opinions are my own views and are not the views of DreamHost.
Any advice offered by me should be acted upon only at your own risk.


#5

Apparently, the location where the file is created really does matter. That’s odd. I had a Python application that wasn’t working and then opened it and added a single space in pico, set the permissions, and it’s working perfectly. Strange…


Jordan M


#6

Apparently, the location where the file is created really does matter. That’s odd. I had a Python application that wasn’t working and then opened it and added a single space in pico, set the permissions, and it’s working perfectly. Strange.

Not so strange, it’s the newline characters. CGIs want unix newline characters and will puke on DOS newlines. Dollars to doughnuts opening it up in pico and re-saving converted the newline characters from DOS to unix.


#7

This can affect a lot of things, besides just python scripts, so it’s good to know. Any text files that I modify on a Windows machine I do so with an editor I can tell “this is a Unix-format file, don’t screw it up!” Vim syntax files are a good example of when format is important.

One of the annoyances with the whole issue is that applications handle the formats differently. A file in “DOS” format viewed on a Linux machine might look just fine, or it might have the funky ^M style characters added, or it might even appear all on one line depending on which program you use.

Check out Gordaen’s Knowledge, the blog, and the MR2 page.


#8

Python scripts have the added issue that whitespace is significant. Changing a series of spaces into a tab can result in a program with a syntax error or one that gives strange output, even though it may look correct on the screen.