【问题标题】:TypeError: cannot concatenate 'str' and 'UUID' objectsTypeError:无法连接“str”和“UUID”对象
【发布时间】:2020-01-11 06:10:21
【问题描述】:

我正在尝试使用 python 脚本更新 cassendra 中的列。

但我收到错误 TypeError: 无法连接 'str' 和 'UUID' 对象

active = session.execute("select id, status from address where status = 'A'")

for row in activeCampaigns:
    session.execute("update address set status = 'ACTIVE' where id = "+row.id);

有人可以帮我解决这个问题吗?

【问题讨论】:

    标签: python python-2.7 cassandra cassandra-2.0 cassandra-3.0


    【解决方案1】:

    row.id 很可能是 UUID 对象。您应该尝试在连接之前将其转换为字符串表示形式:

    session.execute("update ... id = " + str(row.id))
    

    或使用正确的字符串格式:

    session.execute("update ... id = {}".format(row.id))
    

    【讨论】:

    • session.execute("update address set status = %s where id = %s", ('ACTIVE', row.id))
    猜你喜欢
    • 2011-10-23
    • 2015-09-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多