View Full Version : Python setup information
thatinstant
03-24-2008, 11:54 PM
I wanted to share what I learned with getting Python running on my Bluehost site. I want to thank the numerous BH support folks who helped with this and I hope to give back to the BH customer community who are interested in using Python. I went through several iterations of trial and error with and without the BH support group so I really hope this saves someone else from the same frustrations I went through.
1) Before you can continue, please acquire ssh access to your hosting account.
2) Create a python file locally on your computer with the following code from http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52220 :
#!/usr/bin/python
print "Content-type: text/html"
print
print "<pre>"
import os, sys
from cgi import escape
print "<strong>Python %s</strong>" % sys.version
keys = os.environ.keys()
keys.sort()
for k in keys:
print "%s\t%s" % (escape(k), escape(os.environ[k]))
print "</pre>"
3) Create or modify an existing .htaccess file, add the following lines:
AddType text/html py
AddHandler cgi-script .py
4) Save files, upload them both to your public_html folder via sftp/ftp.
5) Assuming that you named the python file, index.py, open an SSH tunnel to your domain, run the following command:
chmod 700 ~/public_html/index.py
6) Navigate to <your domain>/index.py and you should see output of the environment variables and their values.
I really hope this helps!! :)
Hi!
Having got the above working I was happy because I though all I need to do is replicate the arrangement with a different script to run my own scripts. That is- put the script HIWORLD.py in the same directory and address it in the same way. But this gives me a 500 error. Can anyone explain why? and how to get this working?
Thanks,
Paul
PS heres the script im trying to run.
#!/usr/bin/python
print "Content-type: text/html"
print "HI MY WORLD"
and i didnt forget to chmod..
lazynitwit
05-30-2008, 07:30 PM
Hi!
Having got the above working I was happy because I though all I need to do is replicate the arrangement with a different script to run my own scripts. That is- put the script HIWORLD.py in the same directory and address it in the same way. But this gives me a 500 error. Can anyone explain why? and how to get this working?
Thanks,
Paul
PS heres the script im trying to run.
#!/usr/bin/python
print "Content-type: text/html"
print "HI MY WORLD"
and i didnt forget to chmod..
The empty print after the headers is important, it tells the server and browser that the header is over and begins sending content. Leaving it out will result in errors.
#!/usr/bin/python
print "Content-Type: text/html"
print
print "HI MY WORLD"
johnnyWebpages
06-07-2008, 08:15 PM
I wanted to share what I learned with getting Python running on my Bluehost site. I want to thank the numerous BH support folks who helped with this and I hope to give back to the BH customer community who are interested in using Python. I went through several iterations of trial and error with and without the BH support group so I really hope this saves someone else from the same frustrations I went through.
1) Before you can continue, please acquire ssh access to your hosting account.
2) Create a python file locally on your computer with the following code from http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52220 :
#!/usr/bin/python
print "Content-type: text/html"
print
print "<pre>"
import os, sys
from cgi import escape
print "<strong>Python %s</strong>" % sys.version
keys = os.environ.keys()
keys.sort()
for k in keys:
print "%s\t%s" % (escape(k), escape(os.environ[k]))
print "</pre>"
3) Create or modify an existing .htaccess file, add the following lines:
AddType text/html py
AddHandler cgi-script .py
4) Save files, upload them both to your public_html folder via sftp/ftp.
5) Assuming that you named the python file, index.py, open an SSH tunnel to your domain, run the following command:
chmod 700 ~/public_html/index.py
6) Navigate to <your domain>/index.py and you should see output of the environment variables and their values.
I really hope this helps!! :)
Why do you have to have ssh? It won't work if you use the file manager? Thanks.
stardir
07-06-2008, 09:29 AM
Actually with me it doesn't work ...
and I cannot figure out why ... the machines win always :D anyway its quite annoying...the error log says premature ended headers or so ...
____________________________
www.stardir.org (http://www.stardir.org)
stardir
07-06-2008, 08:18 PM
Here is what I've learned - the minimum to run a Python cgi script...
1. The test script you want to run test.py:
#!/usr/bin/python
print "Content-Type: text/html\n\n"
print "<TITLE>CGI Python test script</TITLE>"
print "<H1>Hello, world!</H1>"
2. Upload it in ASCII mode !!! in your cgi-bin directory ...
3. Open the page yourdomain/cgi-bin/test.py ...
So Python runs perfectly on Bluehost ...
__________________________________
www.stardir.org (http://www.stardir.org)
riegersn
03-04-2009, 07:11 PM
Here is what I've learned - the minimum to run a Python cgi script...
1. The test script you want to run test.py:
#!/usr/bin/python
print "Content-Type: text/html\n\n"
print "<TITLE>CGI Python test script</TITLE>"
print "<H1>Hello, world!</H1>"
2. Upload it in ASCII mode !!! in your cgi-bin directory ...
3. Open the page yourdomain/cgi-bin/test.py ...
So Python runs perfectly on Bluehost ...
__________________________________
www.stardir.org (http://www.stardir.org)
Worked like a charm, no other setup or changes required. Thank you :)
Stalyn
03-06-2009, 01:24 PM
how do i get the ssh access?
Early Out
03-06-2009, 03:08 PM
how do i get the ssh access?
From the knowledgebase: How can I get SSH/Shell access on my account? (http://helpdesk.bluehost.com/kb/index.php?x=&mod_id=2&id=203)
Stalyn
03-06-2009, 04:12 PM
From the knowledgebase: How can I get SSH/Shell access on my account? (http://helpdesk.bluehost.com/kb/index.php?x=&mod_id=2&id=203)
thank you.
Stalyn
03-13-2009, 07:50 AM
anyone got it to work without the ssh???
wysiwyg
03-13-2009, 08:17 AM
You don't need ssh for this. In fact you don't even need to chmod the script. If you give it a .cgi extension it changes the permissions to 755 after the first time you access it.
You can chmod through file manager anyway.
I should mention your scripts aren't restricted to cgi-bin either.
Stalyn
03-13-2009, 10:45 AM
You don't need ssh for this. In fact you don't even need to chmod the script. If you give it a .cgi extension it changes the permissions to 755 after the first time you access it.
You can chmod through file manager anyway.
I should mention your scripts aren't restricted to cgi-bin either.
thanks.
I'm new to the python game, i don't want to get dirty with ssh just yet. However, I'm going to get my ssh info for future projects.
bradt
04-12-2009, 09:11 PM
...
chmod 700 ~/public_html/index.py
...
I really hope this helps!! :)
OOPS!
I forgot to CHMOD it and it still works at 644!!
Why?
(i did chmod it to 700 later for security)
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.