Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

python

jquery

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

like image 804
pythoneer Avatar asked Apr 21 '11 16:04

pythoneer


1 Answers

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"
like image 77
vls Avatar answered Sep 29 '22 00:09

vls