You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

AWS Boto3扫描DynamoDB时attribute_not_exists使用报错求助

Boto3 DynamoDB Scan 报错解决

问题代码

currDBraw = table.scan(
  FilterExpression=Attr('purebetId').gt(0) & "attribute_not_exists(ouline)",
  ProjectionExpression="event,homeTeam,awayTeam,startDate,purebetId" 
)

报错信息

AND operation cannot be applied to value attribute_not_exists(ouline) of type <class 'str'> directly

报错原因

  • Boto3的DynamoDB条件表达式必须统一用Attr类的方法构建表达式对象,不能混用字符串形式的函数调用。
  • 你直接把"attribute_not_exists(ouline)"当作条件,它只是普通字符串,无法和Attr('purebetId').gt(0)这个表达式对象执行&(逻辑与)操作。

解决办法

用Attr类的not_exists()方法替代字符串形式的条件,修正后的代码如下:

from boto3.dynamodb.conditions import Attr

currDBraw = table.scan(
  FilterExpression=Attr('purebetId').gt(0) & Attr('ouline').not_exists(),
  ProjectionExpression="event,homeTeam,awayTeam,startDate,purebetId" 
)

注意:代码里的ouline疑似拼写错误(应为outline),如果是笔误请及时修正,否则条件会无法匹配预期数据。

内容的提问来源于stack exchange,提问作者d-z04

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.12 13:12:02