Home > other >  Header file error malformed header from script 'test. Py' : Bad header:
Header file error malformed header from script 'test. Py' : Bad header:

Time:12-03

Did a python script, read the information from the database and then sent to the HTML page,
Using CMD running is no problem, but with the HTML link to open the server internal error will occur and to find the log - error, found the following contents:
18 15:03:03 [Thu Jun., 949984, 2020] [cgi: error] [pid 2348: dar 1768] [client 117.131.117.100:57529] malformed header from script 'test. Py' : Bad header: fname=Mac, lname=Mohan, age=202, and referer: http://www.ppotest.club/test5/test.html

Python file is as follows:
#! C: \ Users \ \ Administrator \ \ AppData \ Local \ designed \ Python Python38 \ Python exe
# - * - coding: utf-8 - * -

# introduction of CGI processing module
The import cgi, cgitb
The import pymysql


Fname=""
Lname=""
Age=""
Sex=""
Income=""

# open database connection
The db=pymysql. Connect (" localhost ", "root", "227191", "TESTDB")

# use the cursor () method to get your cursor
Cursor=the cursor ()

SQL query statement #
SQL="SELECT * FROM employee \
WHERE INCOME & gt; % s "% (1000)
Try:
# executing SQL statements
Cursor. The execute (SQL)
# get all record list
Results=cursor. Fetchall ()
For a row in the results:
Fname=row [0]
Lname=row [1]
Age=row [2]
Sex=row [3]
Income=row [4]
# print the results
Print (" fname=% s, lname=% s, age=% s, sex,=% s income=% s "% \
(fname, lname, age, sex, income))
Except:
Print (" Error: unable to fetch the data ")

# close the database connection
The close ()


Print (" content-type: text/HTML ")
Print ()
Print (" & lt; Html>" )
Print (" & lt; Head>" )
Print (" & lt; GBK meta charset=\ "" & gt;" )
Print (" & lt; title> Cgi test" )
Print (" & lt;/head>" )
Print (" & lt; Body>" )
Print (" & lt; The h2 & gt; Your information is % s, % s, % s, % s, % sPrint (" & lt; Br>" )
Print (" & lt;/body>" )
Print (" & lt;/html>" )



Using CMD running result is as follows:
C: \ Users \ \ Administrator \ Desktop> Python test. Py
Mac, fname=lname=Mohan, age=202, sex=M, income=2000.0
Mac, fname=lname=Mohan, age=20, sex=M, income=2000.0
Mac, fname=lname=Mohan, age=202, sex=M, income=2000.0
The content-type: text/HTML



<meta charset="GBK" & gt;
Cgi test

<body>






Find fault changed in the fourth row from bottom to
Print (" & lt; The h2 & gt; Your information is % s, % s, % s, % s, % sThe log - there is no change in the error of the error,

Internet said print (" content-type: text/HTML ") to print (" content-type: text/HTML \ n \ n ") I changed will not be able to use this, so it's not the problem,

CodePudding user response:

Print () to print ""

CodePudding user response:

refer to the second floor shoppo0505 response:
print () to print ""


Print "" is python2. X version to use, I use the python 3. X version is to use the print ()

CodePudding user response:

Don't know you is how to deal with CGI interface, but from the point of the output, the database part of the code,

 # print resultsPrint (" fname=% s, lname=% s, age=% s, sex,=% s income=% s "% \ 
(fname, lname, age, sex, income))


This is superfluous, will destroy the HTML head, if you need to output three lines, can consider to put into the list, in

 
Print (" & lt; The h2 & gt; Your information is % s, % s, % s, % s, % s


Position to make a for loop,

You try it in the database of the print () commented out, and see whether the program is normal,

  • Related