如何在机器人框架HTTP请求库中为CreateSession添加标头

发布于 2021-01-29 16:18:28

我正在使用此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)
"

我不确定错误来自哪里,因此无法修复

任何故障排除的指针都表示赞赏

关注者
0
被浏览
192
1 个回答
  • 面试哥
    面试哥 2021-01-29
    为面试而生,有面试问题,就找面试哥。

    您没有传递字典,而是传递了看起来像字典的字符串。解决方案是创建一个适当的字典并将其传递给其中。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
    


知识点
面圈网VIP题库

面圈网VIP题库全新上线,海量真题题库资源。 90大类考试,超10万份考试真题开放下载啦

去下载看看