python - 字典更新序列元素#0的长度为1;2 是必需的错误 | Python
问题描述
尝试从字典中获取信息时出现此错误。
#1。这个错误是什么意思?#2。我将如何解决它
这是我当前的代码:
getGroup = requests.get(url = "https://groups.roblox.com/v2/groups?groupIds=" + str(groupId))
req = getGroup.text
print(dict(req)["data"][0])
引发的错误:
Command raised an exception: ValueError: dictionary update sequence element #0 has length 1; 2 is required
请求获得的信息:
{'data': [{'id': 7850173, 'name': 'Project Studios - Roblox', 'description': 'Happy May! \n\nJoin our Communications server to see the progress on our latest projects. \n\nCheck out my friends groups in the Affiliates tab! \n\nFunny Fortnite?\n\n- Group Description Updated 5-1-21 -', 'owner': {'id': 55065985, 'type': 'User'}, 'memberCount': 428, 'created': '2020-09-24T00:01:23.853Z'}]}
如果您能提供帮助,非常感谢!
解决方案
您需要先将 json 响应转换为数据结构。
getGroup = requests.get(url = "https://groups.roblox.com/v2/groups?groupIds=" + str(groupId))
req = getGroup.json()
await ctx.send(dict(req)["data"][0])
推荐阅读
- r - 绘制给定累积分布函数的离散密度
- azure - 停用特定资源的 Azure 安全策略
- python - 如何在 python 中以 pdf 格式下载数据表,同时保持所需的格式?
- java - 使用密钥库 api 的内存密钥库“无法找到到所请求目标的有效证书路径”
- sql - SQL 将表列用于 IN 子句
- php - 创建图像时如何解决“ColorspaceColorProfileMismatch 'icc'”冲突?
- xml - 使用 XML 内容作为请求正文时,如何防止 REST Assured POST 请求丢弃 XML 声明标记?
- excel - 如何在countif公式中使用多个单元格
- reactjs - 修复错误:不变违规:必须在组件内呈现文本字符串 - React Native
- prolog - 仅当 Code Review 中有 2 +2 时如何在 Gerrit 中合并补丁