cancel
Showing results for 
Search instead for 
Did you mean: 
Go to solution
New

How to execute a python script

Heya folks.

 

Firstly, I'm not a python guy. I code in PHP / Asp .net. 

 

I'm trying to get a test script running on my site. 

 

In SSH, I type ">> python" and I see python is installed (2.66).

 

I created a test.py file in the root folder of my website with the following code:

#!/usr/bin/python
print "hello"

 

The file has 755 permissions.

It is written using US ASCII encoding.

 

But it does not execute. And the code is displayed in plaintext in the browser. 

 

Some observations:

/usr/bin/python does not exist when I look for it in SSH. Should it? (I'm using this path in the script because of this help topic: https://www.godaddy.com/help/what-is-the-path-to-python-on-my-hosting-account-644 )

/usr/lib/python2.6 does exist. I don't know the significance of it.

 

Any ideas?

 

Thanks in advance. 

 

Rick

 

3 REPLIES 3
Highlighted
Employee
Employee
Solution

Re: How to execute a python script

I'm not a Python guy myself, but you probably have to add a handler for .py files to your .htaccess. Try this:

 

Options +ExecCGI 
AddHandler cgi-script .py
New

Re: How to execute a python script

Thanks Ben. The file seems to execute now, but I get a 500 error on that file only. I've checked line endings and encoding.

Is there a python error log somewhere?

Rick
New
Solution

Re: How to execute a python script

OK, so I found the error log in cPanel, and I need to chase down the errors now (new territory for me). But python is indeed executing. So, thanks again, BenWTF. Problem solved.

 

Best,

RD