如何在机器人框架 HTTP 请求库中为 CreateSession 添加标头 [英] How to add headers for CreateSession in robot framework HTTP requests library

查看:31
本文介绍了如何在机器人框架 HTTP 请求库中为 CreateSession 添加标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 this 提供的机器人框架中的请求库github链接.该文档暗示 if 可以通过执行 CreateSession 来发送自定义标头.headers={'header1':'value1'} ....但是,当我这样做时,我收到一个错误 ValueError:需要 1 个以上的值才能解压"

I am using the requests library in Robot framework provided at this github link. The documentation implies that if can send custom headers by doing CreateSession <url> headers={'header1':'value1'} .... However, when I do that I get an error "ValueError: need more than 1 value to unpack"

这有效

CreateSession SendCustomHeader http://myhost.com  verify=False 

这个没有

CreateSession SendCustomHeader http://myhost.com headers={'header1':'value1'} verify=False

我尝试了 headers='header1' OR {'header1':'value1'} OR 'header1':'value1' 的各种组合,但出现了相同的错误

I tried with various combinations of headers='header1' OR {'header1':'value1'} OR 'header1':'value1' with same error

请求库代码RequestsKeywords.py中似乎没有错误

There does not seem to be an error in the requests library code RequestsKeywords.py

"        self.builtin.log('Creating session: %s' % alias, 'DEBUG')
        s = session = requests.Session()
        s.headers.update(headers)
"

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

I am not sure where the error is coming from and am therefore unable to fix

感谢任何解决问题的指针

Any pointers to troubleshoot are appreciated

推荐答案

您不是在传递字典,而是在传递一个看起来像字典的字符串.解决方案是创建一个适当的字典并将其传入.机器人有一个 为此目的创建字典关键字.

You aren't passing a dictionary, you're passing a string that looks like a dictionary. The solution is to create a proper dictionary and pass that in. Robot has a Create Dictionary keyword for this purpose.

*** Settings ***
| Library | Collections

*** Test Cases ***
| Example
| | ${headers}= | Create dictionary
| | ... | header1 | value1
| | ... | header2 | value2
| | CreateSession | SendCustomHeader | http://myhost.com  
| | ... | header=${headers} | verify=False 

这篇关于如何在机器人框架 HTTP 请求库中为 CreateSession 添加标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆