pythoneer
pythoneer

Reputation: 81

calling python script from ajax got: malformed header from script. Bad header

I am writting a application using jquery(ajax) and python. When I send the request using ajax to call a php script, everything works. But when I tried to call a python script, I got this error.

malformed header from script. Bad header=AAAAAA

I am not sure what I am missing. The only difference is the type of script ajax is calling.

Following is my php script called:

*<?php
  echo "AAAAA"
?>*

Following is my python script called:

#!/usr/bin/env python
def main():
    print "AAAAAA"

if __name__ == "__main__":
  main()

=========================================== Any idea?

Thanks

Upvotes: 6

Views: 7324

Answers (1)

vls
vls

Reputation: 2319

PHP was designed for web programming so it automatically attaches Content-type to HTTP headers but Python doesn't. Prepend this to main():

print "Content-Type: text/html\n"

Upvotes: 17

Related Questions