繁体   English   中英

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

[英]How to add headers for CreateSession in robot framework HTTP requests library

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

根据请求文档 ,您可以将标头添加到Session对象,如下所示:

s = requests.Session()
s.auth = ('user', 'pass')
s.headers.update({'x-test': 'true'})

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM