python - 如何从 cognito api 响应中获取 phone_no
问题描述
呼唤认知admingetuser
response = client.admin_get_user(
UserPoolId='string',
Username='string'
)
作为回应,我回来response
了
response {'Username': 'xyz@gmail.com',
'UserAttributes': [{'Name': 'sub', 'Value': 'cb0328a8-38fd-4799-84ef-4f7f2733016e'}, {'Name': 'email_verified', 'Value': 'true'},
{'Name': 'phone_number_verified', 'Value': 'false'}, {'Name': 'phone_number', 'Value': '+445115115551'},
{'Name': 'custom:account_id', 'Value': 'a54a936f-d846-44ec-8f6f-c9e127991bda'},
{'Name': 'email', 'Value': 'xyz@gmail.com'}], 'UserCreateDate': datetime.datetime(2018, 12, 10, 13, 46, 47, 533000, tzinfo=tzlocal()),
'UserLastModifiedDate': datetime.datetime(2018, 12, 14, 16, 24, 20, 707000, tzinfo=tzlocal()), 'Enabled': True, 'UserStatus': 'CONFIRMED',
'ResponseMetadata': {'RequestId': '5c649fd3-1005-11e9-b484-433d044b60ba', 'HTTPStatusCode': 200, 'HTTPHeaders': {'date': 'Fri, 04 Jan 2019 09:44:42 GMT',
'content-type': 'application/x-amz-json-1.1',
'content-length': '500', 'connection': 'keep-alive', 'x-amzn-requestid': '5c649fd3-1005-11e9-b484-433d044b60ba'}, 'RetryAttempts': 0}}"
我想从 python 中的这个响应中提取 phone_no 我该怎么做?有什么建议么?
解决方案
根据cognito 文档,响应是 JSON 格式。
因此,您可以简单地将响应解析为 json 使用json.loads(response)
. 这样你可能会得到字典列表。此列表元素之一将是字典包含phone_number
。该字典中键下的值Value
是电话号码。
推荐阅读
- laravel - 我如何“多个” Laravel App 最佳实践
- android - Recyclerview 只刷新显示的项目
- php - 如何根据选定的选项值获取值
- r - covr 显示 0% 的覆盖率,而所有带有 testthat 的测试都通过
- asp.net - ASP.NET 路由 - HTTP 404。您正在寻找的资源(或其依赖项之一)可能已被删除
- google-app-maker - 谷歌应用程序制造商过滤器下拉菜单
- c++ - Boost.Spirit qi值序列向量
- css - Mac中的按钮文本对齐问题
- octobercms - 十月 CMS 无法回滚版本
- jenkins - 詹金斯脚本管道 - 并行 - 多次调用函数