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