Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
字典更新序列元素#0的长度为1;2是必需的错误| Python_Python - Fatal编程技术网

字典更新序列元素#0的长度为1;2是必需的错误| Python

字典更新序列元素#0的长度为1;2是必需的错误| Python,python,Python,我在尝试从字典中获取信息时遇到此错误 #一,。这个错误意味着什么? #2.我该如何着手修理它 这是我目前的代码: getGroup = requests.get(url = "https://groups.roblox.com/v2/groups?groupIds=" + str(groupId)) req = getGroup.text print(dict(req)["data"][0]) 出现错误: Command rais

我在尝试从字典中获取信息时遇到此错误

#一,。这个错误意味着什么? #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])

谢谢你的回复!但是我在尝试从dict获取更多信息时遇到了一个问题。我使用wait ctx.send(dict(req)[“data”][0][“memberCount”][0]),但它似乎不起作用,并引发了错误:“int”对象不可订阅。
req[“data”][0]
对应于列表中的dict,
req[“data”][0][memberCount 0]
对应于将memberCount作为键so 428的元素,这是一个int,是的,您不能在int
getGroup上使用[0]。text
为您提供一个字符串。将字符串转换为dict没有多大意义。您将从
dict(“bsdvdafsf”)
中得到相同的错误。。。