Can't download or see python files


in my dreamhost hosting i cant’ donwload “.py” files, shows me “500 Internal Server Error” and in error.log says: Premature end of script headers

i just want to download the file, help plz :smiley:



What is the permission on the files?

Try 755 on the python files.

Save $97 (MAX Discount) with code: [color=#CC0000]97YES[/color] Sign Up NOW or More Codes Here


Are you trying to execute the Python script, or grab the actual file?

Have you read the Python entry in the Wiki?



changin permission didi’t work :frowning:
i don’t want to execute the file on my hosting, i just want to download it…


How are you trying to “download” these files? Are you using a web browser, or FTP?

It sounds like you are using a browser, and expecting the file to offered as a download when you “left-click” (*doz/*nix) on it (or just click on it in the MAC world).



I’ve not experimented with Python, but if it’s an executable script, I doubt the server will give you the raw file, much like it behaves with a PHP script. Even a right click to save the linked file only gets you the output of that executed file.

Want the raw file? You’re going to have to FTP.
Want the executed output? It sounds like there’s something wrong with your setup. Read up in the Wiki.



i want to download it from a browser like this file:


Yeah, that’s my thinking precisely. I think a couple of workarounds could be useful, such as simply renaming the .py scripts to, or just scriptname.txt (I’ve seen that done a lot to facilitate downloading/display) or changing the handler for .py file via .htaccess.

That’s why I asked what he was trying to do when he said “download” - FTP is what immediately comes to mind for me, but he might have been thinking of something else.



You might want to see my last post in response to Scott.

Have you considered just renaming the “” file to a different extension (they can always be renamed after the download is completed).

Alternately, you could modify your .htaccess to handle .py files in a different way (assuming you are not actually running python scripts on your site). If you are running python scripts on your site using the .py filetype extension, you’ll have to go with the first approach, or some variation of that, or change how you name the .py scripts to be run (and change the handler to “run” those, accordingly, via .htaccess).

Another easy way around this, for making the .py files you are offering as downloads not “run” when “clicked” from within a browser, is to zip, or tar, them into an archive ( so that “” contains a zipped version of “”). This should solve your problem by causing the users’ browsers to handle the “zip” file as a “down loadable” since the server will not try to execute it.



i think that .htaccess solution is better… can you show me how to do it, i don’t know how =(


You didn’t indicate whether you are running any python scripts on your site that use files with a “.py” ending - and I really need to know that to respond to your question completely.

This is because the simplest method of doing what you want to do is to simply use .htaccess to change how the server treats “.py” files. This will, of course, interfere with actually executing any “.py” files that are in, or below, the directory in which you make this fix (unless you reset the handler in the child directory). That said, I’ll bet Google has the answer!

A quick Google search turned up an article called “Stupid htaccess Tricks” from, in the section titled "Instruct server to display source code for dynamic file types:

[quote]There are many situations where site owners may wish to display the contents of a dynamic file rather than executing it as a script. To exercise this useful technique, create a directory in which to place dynamic files that should be displayed rather than executed, and add the following line of code to the htaccess file belonging to that directory. This method is known to work for .pl, .py, and .cgi file-types. Here it is:

RemoveHandler cgi-script .pl .py .cgi [/quote]

In your case, since it is only the .py files you are concerned about, don’t include the “.pl” or the “.cgi”.

The main article has a lot of other useful .htaccess information, and you should refer to the beginning of the article if you need help with .htaccess files in general.

The above fix will allow either the display of the code (for subsequent saving or downloading) and allow the old "right-click to “Save target as” download operation. If you don’t want to allow even the display, check the article carefully for a way to force that (it’s in there too - though I’d advise against doing that!).



In the example he cited, the file has a .py ending. Are you wondering if he’s actually running any .py scripts so that a .htaccess file doesn’t stop those from running, while allowing him to download the ones he doesn’t want to run?

I’m just wondering why he just doesn’t FTP them down. With a Mac, you can just FTP mount your DreamHost home directory and go fishing from there. I presume Windows has a similar setup. Or even just fire up an FTP client.

Another option is one you hinted at and add a .txt extention after the .py. A shell script could go through and find all the .py files and copy them to .py.txt so he’d retain the original Python scripts.



Exactly! If he uses the .htaccess workaround, he’ll have to be careful to keep any .py python files he want to execute out of reach of that .htaccess file. I didn’t want to be responsible for getting him to change his handler in .htaccess and possibly break his python driven site! :wink:

I agree with you on that, and that’s probably a better approach, IMO; I was just trying to answer his question.

Actually, that is what I do when I need this to happen - and your suggestion about a shell script to help with it is a great idea! :slight_smile:



i added RemoveHandler cgi-script .pl .py .cgi to .htaccess and works!

i just needed to download .py files, not to run them…

thanks a lot!


No problem, and I’m glad it worked for you! Just don’t forget you did that 6 months (or two years) from now when you can’t get a python script to run in that directory (or any directory below that one), OK? :wink:



Though this is a very old thread, I wanted to mark that actually, the trick adding ‘.txt’ to a python file doesn’t work anymore. A file like is still submitted for execution. Filenames cannot end on, or contain .pl, .py or .cgi.