How to add headers for CreateSession in robots library

I am using the Robot platform requests library provided by this github link . The documentation implies that if you can send custom headers by executing CreateSession <url> headers={'header1':'value1'} ....

However, when I do this, I get the error "ValueError: needs more than 1 value to unpack"

It works

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

      

Is not

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

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

Seems to be a bug in the RequestsKeywords.py library code

"        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 therefore cannot fix

Any pointers to troubleshooting are appreciated

+3


source to share


2 answers


You are not passing in a dictionary, you are passing in a string that looks like a dictionary. The solution is to create the correct dictionary and convey that. Robot has Create Dictionary 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 

      

+3


source


According to the Requests Documentation, you can add headers to the Session object like:



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

      

-4


source







All Articles