gpt4 book ai didi

python - 从 Python 更新 nvarchar(max) 列时出错

转载 作者:太空宇宙 更新时间:2023-11-03 14:38:28 24 4
gpt4 key购买 nike

我正在更新 Google 反向地理编码的输出(JSON 格式),

cnxn = pyodbc.connect('DRIVER={SQL Server};SERVER=localhost;DATABASE=mydb;UID=test;PWD=abc@123;autocommit=True')
cursor = cnxn.cursor()
wp = urllib.request.urlopen("http://maps.googleapis.com/maps/api/geocode/json?latlng=18.5504,73.9412&sensor=false")
pw = wp.read()
#print(pw)
cursor.execute("UPDATE GEOCODE_tbl SET JSON_str = ? WHERE GEOCODE_ID = ?", pw,749904)
print('Done')
cnxn.commit()

但它给出了错误

('22018', '[22018] [Microsoft][ODBC SQL Server Driver][SQL Server]Operand type clash: image is incompatible with nvarchar(max) (206) (SQLExecDirectW)')

这是什么错误?JSON_str 列具有此类 JSON 输出,因此我正在为那些 JSON_str 列为 NULL 的列执行任务。

有人对此有任何想法吗?

最佳答案

pw不是str类型。尝试将您的查询转换为:

cursor.execute("UPDATE GEOCODE_tbl SET JSON_str = ? WHERE GEOCODE_ID = ?", (str(pw), 749904))

祝你好运!

关于python - 从 Python 更新 nvarchar(max) 列时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46730611/

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