如何使用python从DynamoDB访问和打印二进制字符串类型的数据?

2024-06-07 11:41:44 发布

您现在位置:Python中文网/ 问答频道 /正文

我在AWS DynamoDB中放了一个二进制格式的项目。我的意思是我的数据是加密的,当我试图访问这些数据进行打印或分配时,我不能使用python

import boto3
import base64
dynamodb = boto3.resource('dynamodb', region_name='us-west-2')
table = dynamodb.Table('xyz')

response = table.get_item(
            Key={
                'id': "2",

            }
        )
item = response['Item']
dec_otp=item['otp']

print(dec_otp) #not able to print  
a=dec_otp      #not able to assign

print(type(dec_otp))
print(item)

在输出:-在

^{pr2}$

输出2:

Traceback (most recent call last):
  File "aws_kms3.py", line 25, in <module>
    CiphertextBlob=bytes(base64.b64decode(dec_otp))
  File "/home/vinit/Desktop/kms/venv/lib/python3.6/base64.py", line 80, in b64decode
    s = _bytes_from_decode_data(s)
  File "/home/vinit/Desktop/kms/venv/lib/python3.6/base64.py", line 46, in _bytes_from_decode_data
    "string, not %r" % s.__class__.__name__) from None
TypeError: argument should be a bytes-like object or ASCII string, not 'Binary'

输出3:

Binary object is not itterable

Tags: 数据infrompyimportbyteslinenot

热门问题