简体   繁体   English

在 Robot Framework 中转换为字典会给出错误“ValueError:字典更新序列元素 #0 的长度为 1; 2 是必需的”

[英]Convert To Dictionary in Robot Framework gives the error “ValueError: dictionary update sequence element #0 has length 1; 2 is required”

I cannot seem to find any examples for the Convert To Dictionary keyword so I am not really sure on how to use it.我似乎找不到任何转换为字典关键字的示例,所以我不确定如何使用它。

The following code:以下代码:

 ${newdomain_dict}                 Convert To Dictionary   {'id': 'newdomain', 'entityTypes': ['users', 'msg', 'xmpp']} 

gives the error "ValueError: dictionary update sequence element #0 has length 1; 2 is required"给出错误“ValueError:字典更新序列元素 #0 的长度为 1;需要 2”

The documentation just says this keyword has one argument (item), so I am not sure what this "item" is meant to be - I assumed a string.文档只是说这个关键字有一个参数(项目),所以我不确定这个“项目”是什么意思 - 我假设一个字符串。 Even when I looked on github at the source code this is the impression I got.即使我在源代码中查看 github,这也是我得到的印象。

This is because the argument {'id': 'newdomain', 'entityTypes': ['users', 'msg', 'xmpp']} is treated as a string.这是因为参数{'id': 'newdomain', 'entityTypes': ['users', 'msg', 'xmpp']}被视为字符串。

The documentation for that keyword says this:该关键字的文档是这样说的:

Mainly useful for converting other mappings to normal dictionaries.主要用于将其他映射转换为普通字典。

A string is not a mapping type.字符串不是映射类型。

If you're wanting to define a dictionary via a string, you can use robot's inline python evaluation .如果您想通过字符串定义字典,可以使用机器人的内联 python 评估

${newdomain_dict}  ${{ {'id': 'newdomain', 'entityTypes': ['users', 'msg', 'xmpp']} }}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 鼻子测试错误:ValueError:字典更新序列元素#0的长度为4; 2个为必填项 - nosetest error: ValueError: dictionary update sequence element #0 has length 4; 2 is required ValueError:字典更新序列元素 #0 的长度为 1; 2 是必需的 Python 字典 - ValueError: dictionary update sequence element #0 has length 1; 2 is required Python Dictionary 值错误:字典更新序列元素 #6 的长度为 1; 2 是必需的 - ValueError: dictionary update sequence element #6 has length 1; 2 is required ValueError:字典更新序列元素#0的长度为4; 2是必需的(python) - ValueError: dictionary update sequence element #0 has length 4; 2 is required (python) Python-ValueError:字典更新序列元素#0的长度为15; 2个为必填项 - Python - ValueError: dictionary update sequence element #0 has length 15; 2 is required ValueError:字典更新序列元素#0的长度为1; 2个为必填项 - ValueError: dictionary update sequence element #0 has length 1; 2 is required / admin / login /处的ValueError-字典更新序列元素#0的长度为0; 2个为必填项 - ValueError at /admin/login/ - dictionary update sequence element #0 has length 0; 2 is required ValueError:字典更新序列元素#0的长度为1; 2是必需的 - ValueError: dictionary update sequence element #0 has length 1; 2 is required Python ValueError:字典更新序列元素 #4 的长度为 3; 2 是必需的 - Python ValueError: dictionary update sequence element #4 has length 3; 2 is required 3 ValueError:字典更新序列元素#0的长度为3; 2个为必填项1 - 3 ValueError: dictionary update sequence element #0 has length 3; 2 is required 1
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM