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;
<body>