Jul-28-2021, 11:36 AM
I want to use form with mariadb in python, i want to pass the id from form to mariadb select query to print the selected table row, this is index.html
This is var.py inside the /srv/http/cgi-bin:
<form action = "/cgi-bin/var.py" method = "get"> Row Id: <input type = "number" name = "idn"> <br /> <input type = "submit" value = "Submit" /> </form>
This is var.py inside the /srv/http/cgi-bin:
#!/usr/bin/python
import mariadb
import sys
import configparser
import cgi
import cgitb
# Create instance of FieldStorage
form = cgi.FieldStorage()
mydb = mariadb.connect(
host="localhost",
user="user",
password="",
database="mail"
)
mycursor = mydb.cursor()
query ="SELECT * FROM pop where id=%s"
val = form.getvalue('idn')
mycursor.execute(query, val)
myresult = mycursor.fetchall()
for row in myresult:
print("id = ", row[0])
print("Server = ", row[1])
print("User = ", row[2])
print("Password = ", row[3], "\n")
mycursor.close()
mydb.close() After run the code get this error:Server error! The server encountered an internal error and was unable to complete your request. Error message: End of script output before headers: var.py If you think this is a server error, please contact the webmaster. Error 500 example.com Apache/2.4.48 (Unix) mod_fcgid/2.3.9 mod_wsgi/4.8.0 Python/3.9This is the apache error log:
[Wed Jul 28 15:52:42.397653 2021] [cgi:error] [pid 5430] [client 192.168.1.100:58034] AH01215: Traceback (most recent call last):: /srv/http/cgi-bin/var.py, referer: http://example.com/test/index.html
[Wed Jul 28 15:52:42.397730 2021] [cgi:error] [pid 5430] [client 192.168.1.100:58034] AH01215: File "/srv/http/cgi-bin/var.py", line 5, in <module>: /srv/http/cgi-bin/var.py, referer: http://example.com/test/index.html
[Wed Jul 28 15:52:42.397747 2021] [cgi:error] [pid 5430] [client 192.168.1.100:58034] AH01215: import cgi: /srv/http/cgi-bin/var.py, referer: http://example.com/test/index.html
[Wed Jul 28 15:52:42.397776 2021] [cgi:error] [pid 5430] [client 192.168.1.100:58034] AH01215: File "/srv/http/cgi-bin/cgi.py", line 8: /srv/http/cgi-bin/var.py, referer: http://example.com/test/index.html
[Wed Jul 28 15:52:42.397826 2021] [cgi:error] [pid 5430] [client 192.168.1.100:58034] AH01215: print "Content-Type: text/plain;charset=utf-8\\n\\n": /srv/http/cgi-bin/var.py, referer: http://example.com/test/index.html
[Wed Jul 28 15:52:42.397839 2021] [cgi:error] [pid 5430] [client 192.168.1.100:58034] AH01215: ^: /srv/http/cgi-bin/var.py, referer: http://example.com/test/index.html
[Wed Jul 28 15:52:42.397903 2021] [cgi:error] [pid 5430] [client 192.168.1.100:58034] AH01215: SyntaxError: Missing parentheses in call to 'print'. Did you mean print("Content-Type: text/plain)?: /srv/http/cgi-bin/var.py, referer: http://example.com/test/index.html
[Wed Jul 28 15:52:42.403522 2021] [cgi:error] [pid 5430] [client 192.168.1.100:58034] End of script output before headers: var.py, referer: http://example.com/test/index.html
