Reputation: 6633
I have seen many other answers and tried but they arent helping.
My Python code
#!/usr/bin/env python3
print("Content-Type: text/html")
print()
print ("""
<TITLE>CGI script ! Python</TITLE>
<H1>This is my first CGI script</H1>
""")
Its location and permission
-rwxr-xr-x. 1 root root 161 May 24 02:42 mypython.py
[root@server cgi-bin]# pwd
/var/www/mysite.com/cgi-bin
Virtual-Host conf
[root@server cgi-bin]# cat /etc/httpd/sites-available/mysite.com.conf
<VirtualHost *:80>
ServerName www.mysite.com
DocumentRoot /var/www/mysite.com/public_html
ServerAlias mysite.com
ScriptAlias /cgi-bin/ "/var/www/mysite.com/cgi-bin/"
<Directory /var/www/mysite.com>
Options Indexes FollowSymLinks Includes ExecCGI
AddHandler cgi-script .cgi .py
AllowOverride None
Require all granted
</Directory>
ErrorLog /var/log/httpd/mysite.com/error.log
CustomLog /var/log/httpd/mysite.com/requests.log combined
</VirtualHost>
[root@server cgi-bin]#
While trying to access , I am getting below error
[Wed May 24 02:42:53.958318 2017] [cgid:error] [pid 7943] [client 192.168.56.1:52390] End of script output before headers: mypython.py
[Wed May 24 02:42:54.661338 2017] [cgid:error] [pid 7939] [client 192.168.56.1:52391] End of script output before headers: mypython.py
[Wed May 24 02:42:59.383215 2017] [cgid:error] [pid 7940] [client 192.168.56.1:52392] End of script output before headers: mypython.py
Please let me know if more information required.
Thank you.
Upvotes: 1
Views: 8449
Reputation: 11
I suspect your problem might be the
print()
In Python 2.7.12 at least this prints () and not a blank line as you might expect
Please post the exact output of the script as it is right now.
Upvotes: 1
Reputation: 9430
First of all I take it you web-server is running as root otherwise your execute file permission is wrong.
Secondly if you run the file from the command line it outputs:
Content-Type: text/html
<TITLE>CGI script ! Python</TITLE>
<H1>This is my first CGI script</H1>
Note there are two empty lines not one, this is bad as there should be only one see https://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html
But if you change your code slightly to remove the other empty line it works.
print ("""<TITLE>CGI script ! Python</TITLE>
<H1>This is my first CGI script</H1>
""")
Upvotes: 0