Python 'float64' 无法转换为 MySQL 类型,但在手动查询中没问题

Python 'float64' cannot be converted to a MySQL type but in manual query thats no problem

我有 python 脚本并想像这样将数据插入数据库:

(1, -0.12301105260848999)
(1, 0.07728659361600876)
(1, 0.005048183258622885)
(1, -0.03252531960606575)
(1, -0.05449267476797104)
(1, -0.026811596006155014)
(1, 0.014027083292603493)
(1, -0.10952591896057129)
(1, 0.15669232606887817)
(1, -0.04698480665683746)
(1, 0.26182907819747925)
(1, -0.015784427523612976)

我的 table 没问题,

在那张图片中,我尝试手动将数据插入数据库,并且工作正常。但是在我的 python 脚本中 return 错误:

Failed processing format-parameters; Python 'float64' cannot be converted to a MySQL type

我不知道那有什么问题,因为我手动插入并工作。我使用普通脚本插入数据库,这里是我的脚本:

insert_encode_query = """INSERT INTO encoding_data
                            (id, face_encode)
                            VALUES (%s, %s)"""

    cursor = connection.cursor()
    cursor.executemany(insert_encode_query, detail_encoding)
    connection.commit()

内部变量 detail_encoding :

[(1, -0.12301105260848999), (1, 0.07728659361600876), (1, 0.005048183258622885), (1, -0.03252531960606575), (1, -0.05449267476797104), (1, -0.026811596006155014)]

我的代码有什么问题,或者如何从 python float64 转换为 SQL 类型的 float/decimal,或者任何解决方案?谢谢

据我所知;你应该能够通过使用内置函数将它们转换为 python 数据类型来解决这个问题,所以你传递的内容会像这样:

int(num)

float(decimal)