Python CGI file Read and write Note 500

Source: Internet
Author: User

CGI has a 500 error because the HTTP header is not

GI communication relies on stdout to communicate with the browser.
So simply write inside the py-cgi-index.py:
#!/usr/bin/env python

print ' Hello World '

It is wrong to write like this.
The CGI interface specifies that the CGI script output should begin with an HTTP header.
The character "Hello World" cannot be identified as any valid HTTP header,
Therefore, if you access http://localhost/python-cgi, a 500 error is returned.

There are two solutions:
1, write the HTTP header.
There must be a blank line between the header and the body to identify the front header, followed by the body.
Change the code to:
#!/usr/bin/env python

print ' Content-type:text/html\n\nhello world '
2, blank HTTP header.
If you do not write the HTTP header, Apache will automatically fill in the header.
Change the code to:
#!/usr/bin/env python

print ' \nhello world '


CGI to read and write files, be sure to set the file permissions to 666, that is, all writable.

This article is from the "bio-information spicy" blog, please be sure to keep this source http://mashengwei.blog.51cto.com/1402120/1714959

Python CGI file Read and write Note 500

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.