WebFaction
Community site: login faq

Hi,this is a stupid question, but I'm stuck in the very first part for making a python web application from scratch(CGI)

The code is simple as it can be

#!/usr/local/lib/python2.7
# -*- coding: utf-8 -*-

print "Content-Type: text/plain"
print
print "hello world."

and I get a 500 Internal Server error.
The log says that its a [Premature end of script headers: index.py ] error.
it seems that its working via ssh session.

and as the document says I double checked the permissions which was the correct '711'. also tried other shebangs like

#!/usr/bin/env python2.7

but the result shows the same. sorry for this trivial question.

asked 13 Jun '12, 21:49

Yasushi Sakai
312
accept rate: 0%


Your python script is using DOS line endings (CRLF) instead of unix line endings (LF). To fix this, simply run:

dos2unix index.py

If you're developing on Windows, I would recommend using Geany, Notepad++, or Notepad2, as each can operate in a Unix mode.

Hope that helps!

permanent link

answered 13 Jun '12, 23:05

ryans ♦♦
5.0k93360
accept rate: 43%

Ryan, Thanks for the fast reply! I tried what you mentioned, but the result didn't change...:( both converting the line endings using "dos2unix", and using notepad++.

(14 Jun '12, 02:21) Yasushi Sakai

You should change the shebang line #!/usr/local/lib/python2.7 to #!/usr/local/bin/python2.7. Everything else seems ok.

(14 Jun '12, 02:42) todork

thanks todork! your help worked!!

know I can finally concentrate on python programming.

(14 Jun '12, 06:31) Yasushi Sakai

You are most welcome.

(14 Jun '12, 06:34) todork

I've tried the same index.py of "hello world" with no success. im using the "Static/CGI/PHP-5.4" application

(07 Jan '13, 09:06) Agroinfoti
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×337
×1
×1

question asked: 13 Jun '12, 21:49

question was seen: 7,122 times

last updated: 07 Jan '13, 09:06

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2019 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM