cassandra.protocol.SyntaxException: <来自服务器的错误: code=2000 [CQL 查询中的语法错误] message="行 1:137 输入时没有可行的



我正在尝试将一个zip文件插入到cassandra db的blob存储中。在创建表列时键入workflowid str和存储路径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(?,?);"
pStatement = session.prepare(query)
rslt = session.execute(pStatement, [resultpath, workflowid])

相关内容

最新更新