无法连接到“localhost”上的MySQL服务器。每个套接字地址(协议/网络地址/端口)通常只允许使用一次

2024-10-03 06:27:24 发布

您现在位置:Python中文网/ 问答频道 /正文

我想存储数据自动3秒后,数据将来自生物识别设备的指纹。每隔3秒钟,数据就会自动同步到我的服务器上,但每当我在几秒钟后运行此脚本时,它就会显示此错误比如:可以吗't connect to MySQL server on'localhost'([WinError 10048]每个套接字地址(协议/网络地址/端口)通常只允许使用一次)') 我的代码如下:

def syncAttendanceInfo():
try:
    conn=zk.connect()
    attandance= conn.get_attendance()
    for data in attandance:
        userId= data.user_id
        enrty_time= data.timestamp
        user_status= data.status
        user_punch= data.punch

        my_sql_connection = pymysql.connect(host="localhost", user="root", passwd="", db="android")
        myCursor = my_sql_connection.cursor()
        sql = """INSERT INTO biometric_attandance_info(id,t_time,status,punch) VALUES('%s','%s','%s','%s')""" % (userId,enrty_time,user_status,user_punch)


    myCursor.execute(sql)
    #print("Sync successfully")
    my_sql_connection.commit()
    my_sql_connection.close()







except Exception as e:
    print(e)
finally:
    if conn:
        conn.disconnect()



while True:

try:

    #conn = zk.connect()
    syncAttendanceInfo()#call the function 


except Exception as e:
    print("error")
time.sleep(3)

Tags: 数据localhostsqldatatimemystatusconnect