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
相关产品推荐
相关产品推荐

