gpt4 book ai didi

python - 类型错误 : query() argument 1 must be string or read-only buffer, 不是元组

转载 作者:行者123 更新时间:2023-11-29 18:28:05 26 4
gpt4 key购买 nike

我正在尝试使用 Python MySql DB 更新表的值,但收到此错误。类型错误:query() 参数 1 必须是字符串或只读缓冲区,而不是元组。我不知道我的答案有什么问题。

def id_of_unverifedUniversity():
cur3.execute('select id from universities where verified=0 and deleted=0;')
print "===================Unverififed University================"
for row in cur3.fetchall():
#cur3.execute('SELECT id FROM Users where universityId='+str(row['id']))
print row['id']
query = ('SELECT id FROM users where universityId = %s order by id asc limit 1' %(str(row['id'])))

cur3.execute(query)
result = cur3.fetchall()
for y in result:
if y['id']:
print str(y['id'])
print 'update query statred'
query1 = ("""update universities set updatedBy = %s where id=%s""", (str(y['id']),str(row['id'])))
cur3.execute(query1)

我在查询 1 中遇到此错误

最佳答案

query1中,运算符%似乎丢失了。将变量绑定(bind)到 str

query1 = '''update `universities` set `updatedBy` = %s where `id`=%s''' % (str(y['id']),str(row['id']))

关于python - 类型错误 : query() argument 1 must be string or read-only buffer, 不是元组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45986369/

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