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

后端 未结 2 740
温柔的废话
温柔的废话 2021-01-06 13:45

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 <

相关标签:
2条回答
  • 2021-01-06 14:10

    According to the Requests documentation, you may add headers to the Session object as:

    s = requests.Session()
    s.auth = ('user', 'pass')
    s.headers.update({'x-test': 'true'})
    
    0 讨论(0)
  • 2021-01-06 14:11

    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 
    
    0 讨论(0)
提交回复
热议问题