Jump to content


VlexoFree Notice

Interviews will be open every Friday starting at 12am PDT and lasting for 24 hours.

- - - - -

Simple Python Script Gives HTTP500 Internal Server Error

python cgi 500

  • Please log in to reply
8 replies to this topic

#1 mishmash

mishmash

    Newbie

  • Members
  • 9 posts

Posted 21 January 2012 - 01:12 AM

Hello

I have a simple python script I am trying to execute but when I access the file I get a HTTP500 error. Do I have the wrong Python Shebang?

- The python file has the permissions: 7,5,5
- Following VlexoFrees advice I have looked at my .htaccess file & its empty so it cant be misconfigured(although maybe I need to configure it for python scripts?)
- I have looked at the CPanel error logs but the 500 error isn't documented, it does show/record errors if I try to access the cgi-bin dir, ie, I go to www.selectrecipes.tk/cgi-bin/
- The python file should simply print out: "test"

The file is here: http://www.selectrec...cgi-bin/test.py

The contents of the file are simply:

#!/usr/bin/python2.7
print "content-type: text/html \n\n"
print "test"

Edited by mishmash, 21 January 2012 - 01:17 AM.


Ad Bot


      #2 Eli L

      Eli L

        VlexoFree Owner

      • Owner
      • 6,950 posts
      • LocationWashington, USA

      Posted 21 January 2012 - 08:47 PM

      The path is
      /usr/bin/python
      

      Click your test link again and it works.

      Posted Image


      Please do not PM me for support (unless its a private matter). Instead, post in the appropriate forum and help will be provided accordingly.
      Helpful links: Terms of Service | Privacy Policy | Wiki - Tutorials & Help | VlexoFree Support |


      #3 mishmash

      mishmash

        Newbie

      • Members
      • 9 posts

      Posted 22 January 2012 - 12:34 AM

      Thanks :)

      lol I like your debugging message :P

      Edited by mishmash, 22 January 2012 - 12:43 AM.


      #4 mishmash

      mishmash

        Newbie

      • Members
      • 9 posts

      Posted 23 January 2012 - 02:14 AM

      I am now unable to access/run the script main.py. The weird thing is that main.py contains exactly the same execution code as test.py, but when I access main.py I get a HTTP500 error? I have tested the file & it has no errors so it should execute. Why does this happen?

      http://www.selectrec...cgi-bin/main.py

      The contents of main are:
      #!/usr/bin/python2.7
      import sqlite3
      print "Content-Type: text/plain\n\n"
      print "Eli is awesome"
      print sqlite3.connect("test.db")
      
      """#!/usr/bin/python2.7
      import db.AutoBlogDatabase
      print "content-type: text/html \n\n"
      print "Worked"
      d = db.AutoBlogDatabase.AutoBlogDatabase()
      #d = db.Database.Database()
      print "Worked" """
      

      Edited by mishmash, 23 January 2012 - 02:17 AM.


      #5 Alex C.

      Alex C.

        Advanced Member

      • VlexoFree Support
      • 87 posts
      • LocationCleveland, OH, USA

      Posted 23 January 2012 - 07:08 PM

      Same situation.

      Replace:
      #!/usr/bin/python2.7
      

      with:

      #!/usr/bin/python
      

      This should be for all of the python scripts you write.
      My Blog (Proudly Hosted on VlexoFree) : http://myacblog.tk
      --
      I try to help out the best I can on this forum! (However, Please don't PM me for support. Go here for that!)

      "True Value is in Every Person" - Myself

      #6 mishmash

      mishmash

        Newbie

      • Members
      • 9 posts

      Posted 24 January 2012 - 01:30 AM

      hmm, still doesn't work. I changed the shebang to just
      #!/usr/bin/python
      but its the same HTTP500 error. Python is great but one of the WORST languages get working on webhosts, its never easy with python scripts *sigh.

      Also will the above shebang load python2.7? The module(sqlite3) I am using in that script is only foun in python 2.6 & up.

      PS: I like to look of your blog

      Edited by mishmash, 24 January 2012 - 01:31 AM.


      #7 Eli L

      Eli L

        VlexoFree Owner

      • Owner
      • 6,950 posts
      • LocationWashington, USA

      Posted 24 January 2012 - 10:57 AM

      No, it loads 2.4. Calling 2.7 seemed pretty slow compared to the others when I tried it though.

      You might want to try WSGI. I know that works.

      Posted Image


      Please do not PM me for support (unless its a private matter). Instead, post in the appropriate forum and help will be provided accordingly.
      Helpful links: Terms of Service | Privacy Policy | Wiki - Tutorials & Help | VlexoFree Support |


      #8 Alex C.

      Alex C.

        Advanced Member

      • VlexoFree Support
      • 87 posts
      • LocationCleveland, OH, USA

      Posted 24 January 2012 - 06:41 PM

      Thanks mishmash!
      My Blog (Proudly Hosted on VlexoFree) : http://myacblog.tk
      --
      I try to help out the best I can on this forum! (However, Please don't PM me for support. Go here for that!)

      "True Value is in Every Person" - Myself

      #9 mishmash

      mishmash

        Newbie

      • Members
      • 9 posts

      Posted 25 January 2012 - 12:59 AM

      I got it working! :D

      It's to do with the encoding of the file. If I create a file on cpanel and cut & paste the exact same code from main.py into it then it works. I think the file needs to be utf-8. Weirdly only the file I am accessing has to be the correct encoding, if the file I am accessing imports other python files with incorrect encoding it still works.





      Also tagged with python, cgi, 500

      1 user(s) are reading this topic

      0 members, 1 guests, 0 anonymous users