Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.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
Python 类型错误:不可损坏的类型:';dict';蟒蛇/烧瓶_Python - Fatal编程技术网

Python 类型错误:不可损坏的类型:';dict';蟒蛇/烧瓶

Python 类型错误:不可损坏的类型:';dict';蟒蛇/烧瓶,python,Python,所以,我正在开发一个小程序,该程序应该将值发送到firestore数据库,几乎所有东西都工作正常,但我从这部分代码中得到了一个错误。我正试图保存temp if block == "ITEMS": champs = form.areaItems.data #Get the user input text field from the WTForm (it's a dict for whatever reason) itemsChamps = ItemsChamps

所以,我正在开发一个小程序,该程序应该将值发送到
firestore数据库
,几乎所有东西都工作正常,但我从这部分代码中得到了一个错误。我正试图保存
temp

 if block == "ITEMS":
        champs = form.areaItems.data #Get the user input text field from the WTForm (it's a dict for whatever reason)
        itemsChamps = ItemsChamps(champs.values()) #Stock the dict value inside itemsChamps 
        temp = next(iter(itemsChamps.name)) #Get the 1st value from itemsChamps (I only want the 1st value)
        data = {
            "items": {
                champs: {
                    "string": temp
                }
            }
        }
以下是错误:

File "C:\[..]\flaskblog\routes.py", line 63, in ajouter

"string": temp

TypeError: unhashable type: 'dict'
我的代码可能看起来有点“混乱”,我是个新手,很抱歉

编辑1:现在可以了

我现在觉得自己很笨,我被我写的所有代码弄糊涂了,有一些错误:

        if block == "ITEMS":
        champs = form.itemsFields.data #I was using the wrong form field...
        itemsChamps = ItemsChamps(form.areaItems.data.values()) #I'm now getting all the value from the right field
        temp = next(iter(itemsChamps.name)) #Didn't touch this, it work
        data = {
            "items": {
                champs: {
                    "string": temp
                }
            }
        }

谢谢你给我一点时间

您试图使用dict作为dict键,引用您的评论:“是出于某种原因的dict”。dict是不可散列的,因此不能用作键。可能从dict中提取数据并将其用作键?

您正试图将dict用作dict键,以引用您的评论:“是出于某种原因的dict”。dict是不可散列的,因此不能用作键。可能从dict中提取数据并将其用作键?

问题在于这段代码
champs
是一个字典,您将其用作键,dict键必须是str、int、float(通常是可以散列的,而不是字典)


如果
champs[“用户输入”]
是您感兴趣的数据,您可以将
champs
更改为
champs[“用户输入”]
以解决此问题。

这段代码有问题
champs
是一个字典,您将其用作键,dict键必须是str、int、float(通常是可以散列的,而不是字典)


如果
champs[“用户输入”]
是您感兴趣的数据,您可以将
champs
更改为
champs[“用户输入”]
来解决这个问题。

dict(作为键)中的
champs
不应该是文本字符串
“champs”
?该值已存储在
temp
中。dict(作为键)中的
champs
不应该是文本字符串
“champs”
?该值已存储在
temp
中。
data = {
            "items": {
                champs: {
                    "string": temp
                }
            }
        }