#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2004
    Posts
    14
    Rep Power
    0

    cgi test script to check server


    I am having problems implementing a Python script that works on my pc, but get an internal server error or just displays as text on the web server.(The internal Server error says "Premature end of script header" in the error log.

    The server is equiped with Python 1.5.2(trying to get them to upgrade) @ #!/usr/lib/python.

    http://www.haystar.com/cgi-bin/demreq.py
    http://www.haystar.com/scgi-bin/demreq.py

    Anybody have a suggestion on a simple test script to see if Python is even kicking off.

    Thanks,
    Brett
  2. #2
  3. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    This error happens so often you would have thought more documentation on this error would be around. Anyway what this means is that your program is sending a bad header to Apache.

    Make sure you are putting any raw data before you're headers and that there is a blank line after your headers and it should be fine .

    Mark.
    programming language development: www.netytan.com Hula

  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2004
    Posts
    14
    Rep Power
    0
    I don't have a header() method in my code. Does this mean it needs one?

    I am trying to read up on headers...I don't exactly know what they are and what purpose they serve.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2003
    Location
    Canada
    Posts
    543
    Rep Power
    24
    Try putting

    Code:
    print 'Content-Type: text/html\n'
    after

    Code:
    #/usr/lib/python
  8. #5
  9. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    No, you don't need a header method(). infact this has nothing to do with Python as such. In any CGI program you send headers to the server and the browser so that the software knows what to do i.e. whether the document is html or text. This is done by printing a string that the software understands...

    Code:
    #!/usr/bin/env python
    
    print 'Content-Type: text/html\n' #Conent type header.
    print '<b>Hello Wold</b>'
    Will render a html document which says "Hello Wold"

    Code:
    #!/usr/bin/env python
    
    print 'Content-Type: text/plain\n' #Conent type header.
    print '<b>Hello Wold</b>'
    will render a plain text document saying "<b>Hello Wold</b>\n"

    For more info on this subject check out this thread by roypython.

    http://forums.devshed.com/t127603/s.html

    or search this forum .

    Mark.
    programming language development: www.netytan.com Hula

  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2004
    Posts
    14
    Rep Power
    0
    OK. had that. Thanks for the info on headers. I really want to use Python and learn it more, but I don't know if I will sense I got a Perl script to work with the form in 30 minutes.
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2003
    Location
    Canada
    Posts
    543
    Rep Power
    24
    Python is way better. You're just starting to learn, that's all. Take care!
  14. #8
  15. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    Agreeing with chief; as a language Python outshines perl at nearly every turn! In both clarity and power. However perls CGI package is amazing and Python seems to have been left behind in this respect. Chooseing to turn its attention to other aeas .

    I'm actually working on my own module to make CGI in python easier but it's still in a beta state.

    Mark.
    programming language development: www.netytan.com Hula


IMN logo majestic logo threadwatch logo seochat tools logo