python – 机器人框架传递cookie以获取请求(RequestsLibrary) – TypeError

我需要将cookie值传递给Get request关键字以使其正常工作,但它仍然失败.我不知道如何在那里正确传递它.关键字的文档说明了标题:“标题:与请求一起使用的标题字典”
我使用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}

它总是返回TypeError:字符串索引必须是整数.
追溯:

        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]))

而且我真的需要将cookie传递给请求,否则它只返回登录页面.

非常感谢您的帮助!

解决方法:

Sooo终于找到了解决方案:

    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

关键字创建会话与cookie一起使用,只需将cookie传递给cookie值,但字典JSESSIONID = ${cookie_value}.
或者我不必在创建会话中传递cookie但在Get Request中,我必须将cookie作为字典,如${dict} =
 创建字典Cookie = JSESSIONID = ${cookie_value}并将此传递到Get request session1 / somepage / request headers = ${dict}

上一篇:【移动端debug-6】如何做一个App里的web调试小工具


下一篇:python – 机器人框架测试不运行