How to run Python on X10Hosting

ah-blabla

New Member
Messages
375
Reaction score
7
Points
0
X10Hosting is one of the few free hosting providers allowing Python. Here you will learn how to run python scripts on your website:

1: Make sure your python script has the following as the very first line:
Code:
#!/usr/bin/env python
2. Upload the file (ftp), and make sure it is set as executable: (varies depending on software)
permissions.png


3. Make sure the .htaccess file is set up correctly to allow python to run:
If you placed the script in the cgi-bin directory the script will run directly, otherwise you need to add the following line to the .htaccess file for the directory:
Code:
AddHandler cgi-script .py

4. Enjoy, the script should run.

Note: you should test python scripts locally, and only upload them once they are finished, since debugging on the server isn't easy.


PLEASE NOTE: Python and Perl are not currently (July 2, 2011) enabled on the Free Hosting Servers. You have to have pay to upgrade to at least the Illuminated package. Comparison of Plans.
 
Last edited by a moderator:

ah-blabla

New Member
Messages
375
Reaction score
7
Points
0
For python scripts that are outputting content you will also need to add:
Code:
print "Content-type: text/plain\n"
as the second line, otherwise the script won't send you anything, and you get an error 404.

(Sorry for second post, but it isn't possible to edit the first one.)
 
Last edited:

chony13

New Member
Messages
1
Reaction score
0
Points
0
X10Hosting is one of the few free hosting providers allowing Python. Here you will learn how to run python scripts on your website:

1: Make sure your python script has the following as the very first line:
Code:
#!/usr/bin/env python
2. Upload the file (ftp), and make sure it is set as executable: (varies depending on software)
permissions.png


3. Make sure the .htaccess file is set up correctly to allow python to run:
If you placed the script in the cgi-bin directory the script will run directly, otherwise you need to add the following line to the .htaccess file for the directory:
Code:
AddHandler cgi-script .py

4. Enjoy, the script should run.

Note: you should test python scripts locally, and only upload them once they are finished, since debugging on the server isn't easy.

Thanks
 

galaxyAbstractor

Community Advocate
Community Support
Messages
5,508
Reaction score
35
Points
48
Just a note: most FTP clients aren't using that set-up as shown in the picture, and 755 should be used instead
 

gpstrack

New Member
Messages
10
Reaction score
0
Points
0
The email is sends to me is giving me an error saying:

/usr/bin/env: python
: No such file or directory


Any ideas?
 
Last edited:

rebolli

New Member
Messages
3
Reaction score
0
Points
0
I uploaded a file, script1.py, containing:

Code:
#!/usr/bin/env python

print "Content-type: text/plain\n"
print """\
<html>
<body>
<h2>Hello World!</h2>
</body>
</html>
"""
to my public_html directory. I've added the line
"AddHandler cgi-script .py"
to .htaccess and set the permissions for the file to 755.

But when I try to run it it goes like this: http://olli.x10hosting.com/script1.py
"500 Internal Server Error"

Anyone who knows what's wrong?
 

descalzo

Grim Squeaker
Community Support
Messages
9,373
Reaction score
326
Points
83
1. Do not hijack old threads. Start a new one yourself.
2. The way I do it is:

Code:
#!/usr/bin/env python

print("Content-type: text/html")
print("")

print("<html>")
print("<body>")

print( "Hi there")

print("</body>")
print("</html>")
 
Last edited:

cheezo

Member
Messages
177
Reaction score
0
Points
16
thanks for the tutorial.
hope no one will upload an exploit to my cpanel :D
 

callumacrae

not alex mac
Community Support
Messages
5,257
Reaction score
97
Points
48
They cant upload stuff unless you give them access :)

~Callum
 

chanh.ong25

New Member
Messages
52
Reaction score
0
Points
0
I have done all was suggested but still get this.

.htaccess
AddHandler cgi-script .py

http://ongetc.x10.mx/hello.py

#!/usr/bin/env python
print("Content-type: text/html")
print("")
print("<html>")
print("<body>")
print( "Hi there")
print("</body>")
print("</html>")
Forbidden

You don't have permission to access /hello.py on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

What do you think is the issue?

Thanks
 

marocstream17

New Member
Messages
1
Reaction score
0
Points
0
I have done all was suggested but still get this.

.htaccess
AddHandler cgi-script .py

http://ongetc.x10.mx/hello.py

#!/usr/bin/env python
print("Content-type: text/html")
print("")
print("<html>")
print("<body>")
print( "Hi there")
print("</body>")
print("</html>")
Forbidden

You don't have permission to access /hello.py on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

What do you think is the issue?

Thanks

Got the same issue with the example, both in cgi-bin and regular folder with appropriate .htaccess (AddHandler cgi-script .py), python script with execute permissions.
any idea, folks?
 

descalzo

Grim Squeaker
Community Support
Messages
9,373
Reaction score
326
Points
83
Currently, Perl and Python via cgi are disabled due to repeated abuse by some members. No way around it.

No indication as to if/when they will be enabled again.

EDIT/ADD:

PLEASE NOTE THAT THIS POST IS OVER TWO YEARS OLD. CURRENTLY, PYTHON IS ENABLED.
 
Last edited:
Top