如何在机器人框架HTTP请求库中为CreateSession添加标头
我正在使用此github链接提供的Robot框架中的请求库。该文档暗示,如果可以通过执行此操作发送自定义标头,CreateSession
<url> headers={'header1':'value1'} ....
但是,当我这样做时,我收到一个错误 “
ValueError:需要多个值来解压缩”
这有效
CreateSession SendCustomHeader http://myhost.com verify=False
这不
CreateSession SendCustomHeader http://myhost.com headers={'header1':'value1'}
verify=False
我尝试使用headers =’header1’或{‘header1’:’value1’}或’header1’:’value1’的各种组合进行相同的错误
请求库代码RequestsKeywords.py中似乎没有错误
" self.builtin.log('Creating session: %s' % alias, 'DEBUG')
s = session = requests.Session()
s.headers.update(headers)
"
我不确定错误来自哪里,因此无法修复
任何故障排除的指针都表示赞赏
-
您没有传递字典,而是传递了看起来像字典的字符串。解决方案是创建一个适当的字典并将其传递给其中。Robot为此使用了一个Create
Dictionary关键字。*** Settings *** | Library | Collections *** Test Cases *** | Example | | ${headers}= | Create dictionary | | ... | header1 | value1 | | ... | header2 | value2 | | CreateSession | SendCustomHeader | http://myhost.com | | ... | header=${headers} | verify=False