Я запускаю код с python и данные поступают с него. Я хочу сохранить в MySQL RDS, но у меня есть ошибка:
('Connected to MySQL Server version ', '5.7.26-log')
("You're connected to database: ", (u'attendance1',))
MySQL connection is closed
Traceback (most recent call last):
File "v8.py", line 79, in <module>
mySql_insert_query = ("""INSERT INTO empolyee (ID, Name, date, Similarity) VALUES (%s",%s",%s",%s")""",(n+1, name, date_, smlrty_Prcnt))
NameError: name 'name' is not defined
Код:
import boto3
import io
from PIL import Image
import mysql.connector
from mysql.connector import Error
from mysql.connector import errorcode
n=0
rekognition = boto3.client('rekognition', region_name='eu-west-1')
dynamodb = boto3.client('dynamodb', region_name='eu-west-1')
image = Image.open("sample.jpeg")
stream = io.BytesIO()
image.save(stream,format="JPEG")
image_binary = stream.getvalue()
response = rekognition.search_faces_by_image(
CollectionId='test_Colction',
Image={'Bytes':image_binary}
)
for match in response['FaceMatches']:
smlrty_Prcnt = match['Similarity']
def prnt():
#global name
face = dynamodb.get_item(
TableName='test_Colction_Table',
Key={'RekognitionId': {'S': match['Face']['FaceId']}}
)
if 'Item' in face:
name = (face['Item']['FullName']['S'])
if name == 'basem tarek' :
print'Employee: ', name
date_ = response['ResponseMetadata']['HTTPHeaders']['date']
print 'Date: ', date_
try:
connection = mysql.connector.connect(*********,
user="******",
passwd="******",
database="attendance1")
if connection.is_connected():
db_Info = connection.get_server_info()
print("Connected to MySQL Server version ", db_Info)
cursor = connection.cursor()
cursor.execute("select database();")
record = cursor.fetchone()
print("You're connected to database: ", record)
except Error as e:
print("Error while connecting to MySQL", e)
try:
mySql_insert_query = ("""INSERT INTO empolyee (ID, Name, date, Similarity) VALUES (%s,%s,%s,%s)""",(n+1, name, date_, smlrty_Prcnt))
cursor = connection.cursor()
result = cursor.execute(mySql_insert_query)
connection.commit()
print("Record inserted successfully into table")
cursor.close()
except mysql.connector.Error as error:
print("Failed to insert record into table {}".format(error))
finally:
if (connection.is_connected()):
connection.close()
print("MySQL connection is closed")