0
votes

I'm trying to query my DynamoDB using scan. However, every time I scan it I get the following error:

"Unable to marshal response: Binary(b`long_string_of_random_alphanumerics) is not JSON serializable"

Code:

def login(username, password):
    dynamodb = boto3.resource('dynamodb')
    table = dynamodb.Table('users')
    response = table.scan(
        FilterExpression=Key('username').eq(username)
    )
    items = response["Items"]
    return items

Also, the code doesn't give me the error when I encode "username" bytes(username,"utf-8"). However, the list that it's returning is empty.

Response:
[]

I've ran a query to check if it's getting any items by primary key and it's returning 1 so I'm not really sure what I'm doing wrong here.

    dynamodb = boto3.resource('dynamodb')
    table = dynamodb.Table('users')
    response = table.query(
        KeyConditionExpression=Key('username').eq(username)
    )    
    if response["Count"] == 0:
        return False
    else:
        return True
1

1 Answers

0
votes

I also faced the same issue today, and found a work around:

 response = table.scan(
             FilterExpression = Attr("SS_username").eq(username) & Attr("SS_password").eq(password)
         ) 

    if response["Count"] == 0:
        return False
    else:
        return True

or any other approach someone could share?