Python - shebang line not working

gpstrack

New Member
Messages
10
Reaction score
0
Points
0
I have tried both shebang lines separately:

#!/usr/bin/python
#!/usr/bin/env python

with the following script:

print "Content-type: text/plain\n\n"

def hi():
print "hello"

hi()


Both times I get a 500 error. When I setup a cron to email me the output, I get an error saying:
/usr/bin/python : Bad file name or directory

My subdomain is on .elementfx.com, if that makes a difference?
 

descalzo

Grim Squeaker
Community Support
Messages
9,373
Reaction score
326
Points
83
On Chopin, the path to python shows as

/usr/local/bin/python

edit: 'which' also shows /usr/bin/python

If you are going to run the script from the web, you have to add

AddHandler cgi-script .py

to the .htaccess file.

And, of course, permissions set for execution, 0755

Lastly, some people report problems getting cron jobs to work (usually php or wget).
 
Last edited:

gpstrack

New Member
Messages
10
Reaction score
0
Points
0
Thanks descalzo

I have the Addhandler thing done, and the script is in cgi-bin.
0755, also done. and 0777. still no good.

Anybody else have any thoughts? I will try again tomorrow, just incase the python server is down or whatnot.
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
Both the shebang lines work for me with the sample script (aside: you can use the
Code:
, [html] and [php] tags to delimit & format code samples). The error makes me suspect an issue with the character encoding or line-end discipline. Make sure you save the file as ASCII, not UTF-8, or at least make sure there's no [URL="http://unicode.org/faq/utf_bom.html#BOM"]BOM[/URL]. If you're using FTP to upload the script, make sure you're using ASCII mode so the script uses Unix, rather than DOS, line termination (CR rather than CRLF). DOS line termination should cause an error like the one you're getting.
 
Last edited:

gpstrack

New Member
Messages
10
Reaction score
0
Points
0
that solved it.

i uploaded the file with command line FTP and set the mode to ASCII.

cheers misson!
 
Top