1. <tfoot id='bKxNG'></tfoot>
      <i id='bKxNG'><tr id='bKxNG'><dt id='bKxNG'><q id='bKxNG'><span id='bKxNG'><b id='bKxNG'><form id='bKxNG'><ins id='bKxNG'></ins><ul id='bKxNG'></ul><sub id='bKxNG'></sub></form><legend id='bKxNG'></legend><bdo id='bKxNG'><pre id='bKxNG'><center id='bKxNG'></center></pre></bdo></b><th id='bKxNG'></th></span></q></dt></tr></i><div id='bKxNG'><tfoot id='bKxNG'></tfoot><dl id='bKxNG'><fieldset id='bKxNG'></fieldset></dl></div>

    2. <small id='bKxNG'></small><noframes id='bKxNG'>

      • <bdo id='bKxNG'></bdo><ul id='bKxNG'></ul>

      <legend id='bKxNG'><style id='bKxNG'><dir id='bKxNG'><q id='bKxNG'></q></dir></style></legend>

      机器人框架传递 cookie 以获取请求 (RequestsLibrary

      时间:2023-09-10

          <tbody id='pBiUd'></tbody>

          <small id='pBiUd'></small><noframes id='pBiUd'>

          • <tfoot id='pBiUd'></tfoot>

              <bdo id='pBiUd'></bdo><ul id='pBiUd'></ul>
            • <i id='pBiUd'><tr id='pBiUd'><dt id='pBiUd'><q id='pBiUd'><span id='pBiUd'><b id='pBiUd'><form id='pBiUd'><ins id='pBiUd'></ins><ul id='pBiUd'></ul><sub id='pBiUd'></sub></form><legend id='pBiUd'></legend><bdo id='pBiUd'><pre id='pBiUd'><center id='pBiUd'></center></pre></bdo></b><th id='pBiUd'></th></span></q></dt></tr></i><div id='pBiUd'><tfoot id='pBiUd'></tfoot><dl id='pBiUd'><fieldset id='pBiUd'></fieldset></dl></div>
              1. <legend id='pBiUd'><style id='pBiUd'><dir id='pBiUd'><q id='pBiUd'></q></dir></style></legend>
              2. 本文介绍了机器人框架传递 cookie 以获取请求 (RequestsLibrary) - TypeError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我需要将 cookie 值传递给 Get 请求关键字以使其工作,但它仍然失败.我不确定如何在那里正确传递它.关键字的文档说明了标头:标头:与请求一起使用的标头字典"我有这样的测试,使用库 RequestsLibrary:

                I need to pass cookie value to Get request keyword to make it work, but it is still failing. I am not sure how to pass it correctly there. Documentation of the keyword says about the headers: "headers: a dictionary of headers to use with the request" I have 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}
                

                它总是返回 TypeError: string indices must be integers.追溯:

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

                我确实需要将 cookie 传递给请求,否则它会再次返回仅登录页面.

                And I really need to pass the cookie to the request, because otherwise it returns back only login page again.

                非常感谢您的帮助!

                推荐答案

                Sooo终于找到了解决方案:

                Sooo finally found the 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
                

                关键字 Create Session 与 cookie 一起工作,只是 cookie 不仅必须作为 cookie 值传递,还必须作为字典 JSESSIONID=${cookie_value} 传递.或者,我不必在 Create Session 中传递 cookie,而是在 Get Request 中传递 cookie,然后我必须将 cookie 设为像 ${dict} 这样的字典=创建 Dictionary Cookie=JSESSIONID=${cookie_value} 并将其传递给 Get request session1/somepage/request headers=${dict}

                Keyword Create Session works with the cookie, just the cookie must be passed not just as a cookie value, but dictionary JSESSIONID=${cookie_value}. Alternatively I don't have to pass the cookie in Create Session but in Get Request, just then I have to make the cookie as dictionary like ${dict}= Create Dictionary Cookie=JSESSIONID=${cookie_value} and this pass into Get request session1 /somepage/request headers=${dict}

                这篇关于机器人框架传递 cookie 以获取请求 (RequestsLibrary) - TypeError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:Py.test:对类中的测试用例进行参数化 下一篇:Robot Framework 调用的测试如何将信息返回到控制台

                相关文章

                最新文章

                <tfoot id='kps1v'></tfoot>
                  <legend id='kps1v'><style id='kps1v'><dir id='kps1v'><q id='kps1v'></q></dir></style></legend>
                    <bdo id='kps1v'></bdo><ul id='kps1v'></ul>

                  <i id='kps1v'><tr id='kps1v'><dt id='kps1v'><q id='kps1v'><span id='kps1v'><b id='kps1v'><form id='kps1v'><ins id='kps1v'></ins><ul id='kps1v'></ul><sub id='kps1v'></sub></form><legend id='kps1v'></legend><bdo id='kps1v'><pre id='kps1v'><center id='kps1v'></center></pre></bdo></b><th id='kps1v'></th></span></q></dt></tr></i><div id='kps1v'><tfoot id='kps1v'></tfoot><dl id='kps1v'><fieldset id='kps1v'></fieldset></dl></div>

                    <small id='kps1v'></small><noframes id='kps1v'>