如何在机器人框架 HTTP 请求库中为 CreateSession 添加 headers
How to add headers for CreateSession in robot framework HTTP requests library
我正在使用 this github link 提供的 Robot 框架中的请求库。该文档暗示如果可以通过 CreateSession <url> headers={'header1':'value1'} ....
发送自定义 headers
但是,当我这样做时,出现错误 "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' 的各种组合错误
请求库代码好像没有错误RequestsKeywords.py
" self.builtin.log('Creating session: %s' % alias, 'DEBUG')
s = session = requests.Session()
s.headers.update(headers)
"
我不确定错误的来源,因此无法修复
感谢任何解决问题的建议
根据 Requests documentation,您可以将 headers 添加到 Session object 为:
s = requests.Session()
s.auth = ('user', 'pass')
s.headers.update({'x-test': 'true'})
您传递的不是字典,而是看起来像字典的字符串。解决方案是创建一个合适的字典并将其传入。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
我正在使用 this github link 提供的 Robot 框架中的请求库。该文档暗示如果可以通过 CreateSession <url> headers={'header1':'value1'} ....
发送自定义 headers
但是,当我这样做时,出现错误 "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' 的各种组合错误
请求库代码好像没有错误RequestsKeywords.py
" self.builtin.log('Creating session: %s' % alias, 'DEBUG')
s = session = requests.Session()
s.headers.update(headers)
"
我不确定错误的来源,因此无法修复
感谢任何解决问题的建议
根据 Requests documentation,您可以将 headers 添加到 Session object 为:
s = requests.Session()
s.auth = ('user', 'pass')
s.headers.update({'x-test': 'true'})
您传递的不是字典,而是看起来像字典的字符串。解决方案是创建一个合适的字典并将其传入。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