[英]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.