【发布时间】:2017-10-13 13:02:32
【问题描述】:
我正在更新 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))? -
@FlipperPA 是的,将它们转换为 str 工作。非常感谢!!!
-
太好了,我会把它转换成答案!
标签: python json python-3.x pyodbc