簡體   English   中英

cassandra.protocol.SyntaxException:

[英]cassandra.protocol.SyntaxException: <Error from server: code=2000 [Syntax error in CQL query] message="line 1:137 no viable alternative at input

我正在嘗試將 zip 文件插入到 cassandra db 的 blob 存儲中。 在創建表列時輸入workflowid str 和savepath blob

嘗試:

bin_data = open('4e9b-9c08-e3cafafd871b-20211129034556.zip', 'rb').read()
print(type(bin_data))
#hex_data = codecs.encode(bin_data, "hex_codec")
#print(type(hex_data))
auth_provider = PlainTextAuthProvider(username = username , password = password)
cluster = Cluster(contact_points = [ip], port=1234, auth_provider = auth_provider)
session = cluster.connect("keyspace")
session.row_factory = dict_factory
resultpath = bin_data
workflowid = "d6fe8ea4-fffd"
query = "insert into tablename(resultpath, workflowid) VALUES({resultpath}, '{workflowid}');".format(resultpath, workflowid)
rslt = session.execute(query, timeout=None)
df = pd.DataFrame(rslt)
print(df)

except Exception as E:
    print("Error: ", str(E))

BLOB 中的某些數據似乎沒有正確轉義。嘗試使用准備好的語句,而不是:

query = "insert into tablename(resultpath, workflowid) VALUES(?,?);"
session.prepare(query)
rslt = session.execute(query, [resultpath, workflowid])

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM