Question

I'm trying to host a python script using an apache web server, but the server tries to run the script instead of just offering it for download.

I do not have direct access to server, and adding the line

AddType text/plain .py

to .htaccess in the root folder does not appear to work, though I could be doing something wrong.

How do I get the server to just send the file as text instead of trying to run it?

-Edit

Changing the name does not work. Script.py.safe still give a 500 Server error when you click it.

I should also mention that the .htaccess file does work, but for some reason that one addType line is not working. Either because it's not overriding something, or the line is wrong.

Was it helpful?

Solution

In your .htaccess:

RemoveHandler .py

OTHER TIPS

If you can't change the Apache config and you can't override it with an htaccess file, then it seems to me that the easiest solutions would be either to change the file extension, or else to write a script that prints the contents of the target script.

Both are hacks to some extent, but the correct solution is to change the Apache config.

One option is to change the extention and make clear that it should be renamed. IE python.py.safe or python.py.dl. The user would then need to remove the extra bit.

You could also Zip it up.

I would write something that loads the python script up. This way you could even get energetic and include formatting and styling of the code. You could even write it in python since you will not have precluded that by file extension.

<IfModule mime_module>
    <Files *.py>
        ForceType text/plain
    </Files>
</IfModule>

in a .htaccess for the folder should work ;)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top