openstack - 使用 keystoneclient 模块为用户设置 MFA 选项
问题描述
我正在尝试使用 Python keystoneclient API keystoneclient.users.update为 Openstack 用户启用默认 MFA
我有来自 Openstack 文档的示例 API curl 命令,您可以在其中使用 JSON 对象更新用户帐户的“选项”属性
{
"user": {
"options": {
"multi_factor_auth_enabled": true,
"multi_factor_auth_rules": [
["password", "totp"]
]
}
}
}
当我尝试在 Python 代码中更新相同的内容时,出现以下错误
keystoneauth1.exceptions.http.BadRequest:字段'options'的输入无效:u'{“multi_factor_auth_enabled”:true,“multi_factor_auth_rules”:[[“password”,“totp”]]}'不是'object'类型
在架构 ['properties']['options'] 中验证 'type' 失败:
我的代码是这样的
MFA_dict = '{ "multi_factor_auth_enabled": true, "multi_factor_auth_rules": [["password", "totp"]]}'
user = keystone.users.update(user_id, options=MFA_dict)
解决方案
没关系,我想通了。MFA_dict 是字符串,所以我只需要删除单引号并制作对象字典。
并将小写 true 变为大写True以使其成为布尔值
MFA_dict = { "multi_factor_auth_enabled": True, "multi_factor_auth_rules": [["password", "totp"]]}
推荐阅读
- node.js - Nodejs 使用 Sequelize。“[].belongsTo 调用的不是 Sequelize.Model 在 Function 的子类。”
- java - 从三个侧面计算的角度仅显示 90 或 180 度
- c# - 如何在winforms中将嵌套列表绑定到datagridview
- python - 如何在python中将子列表和字符串结合起来列出
- javascript - 在我的所有代码都应该完成之后执行的 Javascript 代码
- python - 名单中的棋子宣布获胜者
- quill - 需要一种使用自定义按钮切换段落(块)类的方法
- java - 内容解析器无法在平板设备上运行
- list - 选择 Dropdown Googlesheets 脚本后从列表中删除项目
- node.js - 从 node_modules 位置以外的位置解析 nodejs 模块,有可能吗?