Robot framework passes cookie to receive request (RequestsLibrary) - TypeError

I need to pass a cookie value to get the request keyword for it to work, but it still doesn't work. I'm not sure how to convey it correctly. The keyword documentation says about headers: "headers: a dictionary of headers to use with a request" I have a test like this using Library RequestsLibrary

:

Check request and response
    Do Local Login  ${username}    ${password}  #this is my custom keyword - opens browser and logs in using UI
    ${cookie_value}=  Get Cookie Value  JSESSIONID
    Create Session  session1  https://oururl.com  verify=${False}  cookies=${cookie_value}
    ${dict}=  Create Dictionary   Cookie=${cookie_value}
    ${resp}=  Get request  session1  /somepage/request  headers=${dict}

      

It always returns TypeError: string indices must be integers

. Traceback:

        Traceback (most recent call last):
  File "c:\python27\lib\site-packages\RequestsLibrary\RequestsKeywords.py", line 370, in get_request
    session, uri, params, headers, json, redir, timeout)
  File "c:\python27\lib\site-packages\RequestsLibrary\RequestsKeywords.py", line 897, in _get_request
    verify=self.verify)
  File "c:\python27\lib\site-packages\requests\sessions.py", line 501, in get
    return self.request('GET', url, **kwargs)
  File "c:\python27\lib\site-packages\requests\sessions.py", line 474, in request
    prep = self.prepare_request(req)
  File "c:\python27\lib\site-packages\requests\sessions.py", line 385, in prepare_request
    cookies = cookiejar_from_dict(cookies)
  File "c:\python27\lib\site-packages\requests\cookies.py", line 518, in cookiejar_from_dict
    cookiejar.set_cookie(create_cookie(name, cookie_dict[name]))

      

And I really need to pass the cookie per request, because otherwise it will only return to the login page again.

Thanks a lot for any help!

+3


source to share


1 answer


Finally Sooo found a solution:

    Do Local Login  ${username}    ${password}
    ${cookie_value}=  Get Cookie Value  JSESSIONID
    ${dict}=  Create Dictionary   JSESSIONID=${cookie_value}
    Create Session  session1  https://oururl.com  verify=${False}  cookies=${dict}
    ${resp}=  Get request  session1  /somepage/request

      



The keyword Create Session

works with a cookie, only the cookie must be passed not only as a cookie value, but also a dictionary JSESSIONID=${cookie_value}

. Alternatively, I don't need to pass the cookie to Create Session

, but to Get Request

, just then I have to make the cookie as a dictionary for example ${dict}= Create Dictionary Cookie=JSESSIONID=${cookie_value}

and this transition toGet request session1 /somepage/request headers=${dict}

+5


source







All Articles