Web Hosting Forum | Lunarpages

Author Topic: Need help running this basic python script :)  (Read 7139 times)

Offline PeteSki

  • Space Explorer
  • ***
  • Posts: 6
Need help running this basic python script :)
« on: September 23, 2014, 04:08:41 AM »
Hi there,

I'm just having heaps of trouble getting this basic python script to work from my webspace and I was wondering if someone could point me in the right direction.
I'm sure I've had this working before but now I can't for the life of me get it to work :(

This is the script i am running to test -
Code: [Select]
#!/usr/bin/python
print 'Content-type: text/html'
print 'hello'

I made sure the permissions were set to 0755 and it's located in my cgi-bin folder. but whenever I run it I get -
Internal Server Error

Any idea's what I might be doing wrong here?
Thanks,
Pete


Offline MrPhil

  • Senior Moderator
  • Berserker Poster
  • *****
  • Posts: 6232
Re: Need help running this basic python script :)
« Reply #1 on: September 24, 2014, 02:06:05 PM »
I can't say I have much experience wrangling this kind of snake, but I'll take a couple of guesses...

1. You've double checked your permissions? A 500 Error can be the result of write permission to "world"/"other". And if you used an FTP client to change permissions, a chmod request might have been silently ignored.

2. Have you double checked the location of the python interpreter? I would go so far as to run a find / -name python -print 2>/dev/null, as a one-time cron job if you don't have SSH access, and confirm /usr/bin/python exists. You might also do a ls -la /usr/bin/python just to confirm that you're allowed to run it.
Visit My Site

E-mail Me
  
-= From the ashes shall rise a sooty tern =-

Offline gavind

  • Spaceship Navigator
  • *****
  • Posts: 98
Re: Need help running this basic python script :)
« Reply #2 on: September 27, 2014, 09:13:05 AM »
Hi PeteSki, any luck on this so far for you? Would be nice if you can share the steps if you were able to fix this already.

Offline PeteSki

  • Space Explorer
  • ***
  • Posts: 6
Re: Need help running this basic python script :)
« Reply #3 on: September 30, 2014, 02:54:37 AM »
No not yet  :(
I've double checked the permissions (I'm changing them through CPanel file manager) and they are 0755.
It's weird because I had a simple .py script working once before, but then i was somehow broke it and haven't been able to get it going since...
I'm going to have another look at it tonight and see if I can get it working, if I get anywhere I'll post it here.

Pete

edit : Also I got the lunar pages python dir from here (http://wiki.lunarpages.com/Special_Server_Paths)

« Last Edit: September 30, 2014, 02:57:50 AM by PeteSki »

Offline PeteSki

  • Space Explorer
  • ***
  • Posts: 6
Re: Need help running this basic python script :)
« Reply #4 on: September 30, 2014, 03:13:26 AM »
Okay! I had some luck!

Code: [Select]
#!/usr/bin/python
print "Content-type: text/html\n"
print "Hello!"

So it looks like the print 'Content-type: text/html' was wrong and this worked print "Content-type: text/html\n"
Not too sure why that was? I thought \n just meant next line...

Thanks for the help!
Pete

Offline MrPhil

  • Senior Moderator
  • Berserker Poster
  • *****
  • Posts: 6232
Re: Need help running this basic python script :)
« Reply #5 on: September 30, 2014, 05:14:39 AM »
In many languages, ' and " delimiters on strings are treated differently. For example, \n (newline) is expanded within " but not '.  I would guess that the \n is critical to separating the "header" from the content of the page.
Visit My Site

E-mail Me
  
-= From the ashes shall rise a sooty tern =-

Offline PeteSki

  • Space Explorer
  • ***
  • Posts: 6
Re: Need help running this basic python script :)
« Reply #6 on: October 01, 2014, 02:23:43 AM »
Yeah, must be!
Well thanks for the help,
Pete

 

Share |