1

I am new to PYTHON and usually code on PHP. This is the first script I am trying to run on Windows XAMPP. I enabled addhandler for .py and trying to run the following script:

#!C:\Python33\python.exe
# enable debugging
import cgitb
cgitb.enable()
print ("Content-Type: text/html;charset=utf-8")
print ("Hello World!")

and I am getting the following error while running the code:

The server encountered an internal error and was unable to complete your request.

Error message: malformed header from script 'test.py': Bad header: Hello World!

If you think this is a server error, please contact the webmaster.

1
  • 1
    Try not to re-invent the wheel - I suggest you use a framework instead of doing things by hand. flask is a great lightweight framework to start with. Commented Aug 30, 2013 at 10:41

2 Answers 2

2

You should separate headers from body printing additional newline:

#!C:\Python33\python.exe
import cgitb
cgitb.enable()
print("Content-Type: text/html;charset=utf-8")
print() # <----------- addtional newlnie for header/body separation.
print("Hello World!")
Sign up to request clarification or add additional context in comments.

Comments

2

For anyone who's still getting an error, try replacing print() by print("\r\n") in the following way:

print("Content-Type: text/html;charset=utf-8")
print("\r\n")
print("Hello World!")

This should work!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.