gpt4 book ai didi

python - 获取类型错误 TypeError : not all arguments converted during string formatting python

转载 作者:行者123 更新时间:2023-11-29 04:21:06 25 4
gpt4 key购买 nike

<分区>

我正在将特定数据从 .xls 文件转储到 mysql 数据库。尝试时出现以下错误。

我的 .py 文件

import xlrd
import MySQLdb
book = xlrd.open_workbook("Sheet2.xls")
sheet = book.sheet_by_name("Sheet1")
database = MySQLdb.connect (host="localhost", user="root", passwd="", db="dtz_new")
cursor = database.cursor()
query = """INSERT INTO property_property(name) VALUES(%s)"""
for r in range(1, sheet.nrows):
gaurav = sheet.cell(r,1).value
values = (gaurav)
cursor.execute(query, values)
cursor.close()
database.commit()
database.close()
print "all done, Bye for now"
columns = str(sheet.ncols)
rows = str(sheet.nrows)
print "I just imported "+ columns+ " columns and "+ rows+" rows to MySQL!"

我得到的错误在这里

Traceback (most recent call last):
File "dtz_db.py", line 29, in <module>
cursor.execute(query, values)
File "c:\Python27\lib\site-packages\MySQLdb\cursors.py", line 187, in execute
query = query % tuple([db.literal(item) for item in args])
TypeError: not all arguments converted during string formatting

单元格(1,1)的值是 Kunjvihar 它是 python 中的一个名称 charfield请帮我解决这个问题

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com