我不知道这条insert语句做错了什么。我得到的错误是:
"Failed processing format-parameters; %s" % err)
mysql.connector.errors.ProgrammingError: Failed processing format-parameters;
'MySQLConverter' object has no attribute '_navigablestring_to_mysql'`具体的代码行如下:
update = '''INSERT INTO myDB.newtable (ID,Record,Latitude,Longitude,code) VALUES (%s,%s,%s,%s,%s)'''
cursor2.execute(update,(ID,Record,Latitude,Longitude,code))
cnx2.commit()我也尝试过这种格式:
update = ("INSERT INTO myDB.newtable (ID,Record,Latitude,Longitude,code) VALUES (%s, %s, %s, %s, %s)")%(ID,Record,Latitude,Longitude,code)
cursor2.execute(update)并得到这个错误:mysql.connector.errors.ProgrammingError: 1054 (42S22): Unknown column '45676kb' in 'field list'。
45676kb只是整个值的一部分。完整的字符串是45676kb-98734-98734-123nn。
我认为第二次尝试的语法更正确,因为我至少得到了一个sql错误,但是我不知道如何用mysql.connector正确地格式化insert语句。
发布于 2016-05-03 03:06:21
第一种选择是将查询参数放入查询中的正确方法-它称为参数化查询。在本例中,您让数据库驱动程序转义查询参数,将它们安全地插入到查询中,并处理从Python到MySQL的类型转换。
您得到的错误意味着它无法将ID、Record、Latitude、Longitude或code参数值之一转换为有效的MySQL数据库类型。具体地说,请参阅您发布的变量类型:
ID <type 'unicode'>
Record <type 'unicode'>
Latitude <class 'bs4.element.NavigableString'>
Longitude <class 'bs4.element.NavigableString'>
code <type 'unicode'>问题出在Latitude和Longitude --它们是BeautifulSoup的NavigableString类实例-- MySQL转换器很难理解如何将NavigableString对象转换为有效的MySQL类型。
update = """
INSERT INTO
myDB.newtable
(ID,Record,Latitude,Longitude,code)
VALUES
(%s,%s,%s,%s,%s)
"""
cursor2.execute(update, (ID, Record, str(Latitude), str(Longitude), code))https://stackoverflow.com/questions/36989671
复制相似问题