此代码未在表中插入任何值。我不懂为什么。请帮忙。 PS-它可以正常运行并显示true,但不会插入任何内容。
import face_recognition
import MySQLdb
db = MySQLdb.connect(
host="localhost", # your host, usually localhost
user="root", # your username
passwd=" ", # your password
db="staticdb", # name of the data base
)
cur = db.cursor()
picture_of_me = face_recognition.load_image_file(
"/Applications/XAMPP/htdocs/akriti/student_images/201501431/reference/201501431.png"
)
my_face_encoding = face_recognition.face_encodings(picture_of_me)[0]
# my_face_encoding now contains a universal 'encoding' of my
# facial features that can be compared to any other picture of a face!
unknown_picture = face_recognition.load_image_file(
"/Applications/XAMPP/htdocs/akriti/student_images/201501431/2018-05-03_100/201501431.jpg"
)
unknown_face_encoding = face_recognition.face_encodings(unknown_picture)[0]
# Now we can see the two face encodings are of the same person with `compare_faces`!
results = face_recognition.compare_faces(
[my_face_encoding], unknown_face_encoding
)
if results[0] == True:
cur.execute(
"""insert into attendance (StudentId,TheDate,CourseId) values (%s,%s,%s) """,
("201501890", "2018-05-03", "100"),
)
print("true")
db.commit()
答案 0 :(得分:0)
查询末尾有一个逗号。不知道是为了什么但是尝试一下。这应该工作。
cur.execute("INSERT INTO attendance (StudentId,TheDate,CourseId) VALUES (%s,%s,%s)", ('201501890','2018-05-03','100'))