我想从 python 中的字典对象下方获取特定键 (sp_puser,sp_pkey) 的值 任何人都可以建议
I want get value for specific key(sp_puser,sp_pkey) from below dictionary object in python can anyone suggest
{
'ARN': 'arn:aws:secretsmanager:us-west-1:704532713440543:secret:mysecret-XUXMVY',
'Name': 'mysecret',
'VersionId': 'h5757v76-6666-9977-0099-7jhhhvnb987967',
'SecretString': '{"sp_puser":"ALKJLK897MNVMJH2YU","sp_pkey":"dsjjhGHkjhjg7GJchjchkh"}',
'VersionStages': ['AWSCURRENT'],
'CreatedDate': datetime.datetime(2021, 6, 17, 15, 7, 48, 971000, tzinfo=tzlocal()),
'ResponseMetadata': {
'RequestId': 'h5757v76-6666-9977-0099-7jhhhvnb987967',
'HTTPStatusCode': 200,
'HTTPHeaders': {
'date': 'Thu, 24 Jun 2021 12:59:41 GMT',
'content-type': 'application/x-amz-json-1.1',
'content-length': '343',
'connection': 'keep-alive',
'x-amzn-requestid': 'h5757v76-6666-9977-0099-7jhhhvnb987967'
},
'RetryAttempts': 0
}
}
这是一个JSON字符串,使用json.loads()
解析它。
data = {
# ...
'SecretString': '{"sp_puser":"ALKJLK897MNVMJH2YU","sp_pkey":"dsjjhGHkjhjg7GJchjchkh"}',
# ...
}
import json
secret_string = json.loads(data["SecretString"])
print(secret_string["sp_puser"]) # ALKJLK897MNVMJH2YU
print(secret_string["sp_pkey"]) # dsjjhGHkjhjg7GJchjchkh
{
'ARN': 'arn:aws:secretsmanager:us-west-1:704532713440543:secret:mysecret-XUXMVY',
'Name': 'mysecret',
'VersionId': 'h5757v76-6666-9977-0099-7jhhhvnb987967',
'SecretString': '{"sp_puser":"ALKJLK897MNVMJH2YU","sp_pkey":"dsjjhGHkjhjg7GJchjchkh"}',
'VersionStages': ['AWSCURRENT'],
'CreatedDate': datetime.datetime(2021, 6, 17, 15, 7, 48, 971000, tzinfo=tzlocal()),
'ResponseMetadata': {
'RequestId': 'h5757v76-6666-9977-0099-7jhhhvnb987967',
'HTTPStatusCode': 200,
'HTTPHeaders': {
'date': 'Thu, 24 Jun 2021 12:59:41 GMT',
'content-type': 'application/x-amz-json-1.1',
'content-length': '343',
'connection': 'keep-alive',
'x-amzn-requestid': 'h5757v76-6666-9977-0099-7jhhhvnb987967'
},
'RetryAttempts': 0
}
}
这是一个JSON字符串,使用json.loads()
解析它。
data = {
# ...
'SecretString': '{"sp_puser":"ALKJLK897MNVMJH2YU","sp_pkey":"dsjjhGHkjhjg7GJchjchkh"}',
# ...
}
import json
secret_string = json.loads(data["SecretString"])
print(secret_string["sp_puser"]) # ALKJLK897MNVMJH2YU
print(secret_string["sp_pkey"]) # dsjjhGHkjhjg7GJchjchkh