2017-10-13 38 views
1

我更新谷歌的输出反地理编码(这是JSON格式)更新为nvarchar(max)列,错误从Python的

cnxn = pyodbc.connect('DRIVER={SQL Server};SERVER=localhost;DATABASE=mydb;UID=test;[email protected];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的那些列执行任务。

有没有人有任何想法呢?

+2

你确定'pw'的类型是'str'吗?可能试试'cursor.execute(“UPDATE GEOCODE_tbl SET JSON_str =?WHERE GEOCODE_ID =?”,(str(pw),749904))'? – FlipperPA

+0

@FlipperPA是将它们转换为str工作。非常感谢!!! – deepesh

+1

太好了,我会将其转换为答案! – FlipperPA

回答

1

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

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

祝你好运!