Incorrect title from script index.py Bad title

I want to run python code on apache2 server (ubuntu 14.04). I followed these steps and received an error message:

Step 1:

Configuration 1: I created a directory and a file under

/var/www/cgi-bin

Configuration 2: I edited / etc / apache 2 / sites-available / 000-default.conf

Alias /cgi-bin /var/www/cgi-bin
<Directory "/var/www/cgi-bin">
Options Indexes FollowSymLinks ExecCGI
AddHandler cgi-script .cgi .py
Allow from all
</Directory>

<Directory /var/www/cgi-bin>
Options All
</Directory>

Step 2:

and my python script: index.py

#!/usr/bin/env python
import cgi;
import cgitb;cgitb.enable()

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

print "<b>Hello python</b>"

Step 3:

When I launched the Chrome browser using: URL: http: //localhost/cgi-bin/index.py

step 4:

I get this error in the error log

malformed header from script 'index.py': Bad header: Hello Python
+4
source share
2 answers

You must finish your headline \r\n, then you must print another one \r\nto signal that the body is approaching.

( , , )

+11

script

#!/usr/bin/env python
import cgi;
import cgitb;cgitb.enable()

print "Content-Type: text/html"
print "" #use this double quote print statement to add a blank line in the script
print "<b>Hello python</b>"

html . html- script.

+1

Source: https://habr.com/ru/post/1624558/


All Articles