gpt4 book ai didi

python - 在机器人框架中添加授权 header

转载 作者:太空宇宙 更新时间:2023-11-04 09:36:08 25 4
gpt4 key购买 nike

我正在学习机器人框架、API 自动化:

*** Settings ***
Library RequestsLibrary
Library Collections
Library String

*** Variables ***
${headers} Create Dictionary Authorization Bearer abcde


*** Test Cases ***
Make a simple REST API call
[Tags] API
Create Session my_json http://localhost:3000
Log ${headers}
${response} = Get Request my_json /posts headers=${headers}
Log ${response}
# Check the Response status
Should Be Equal As Strings ${response.status_code} 403
# ${response} = Get Request my_json /posts

${json} = Set Variable ${response.json()}
Log ${json}
Log len(${json})
Should Be Equal As Strings ${json['name']} rajesh

我在 log.html 中收到这个错误

Documentation: Send a GET request on the session object found using the given alias

Start / End / Elapsed: 20181209 18:43:04.159 / 20181209 18:43:04.175 / 00:00:00.016 18:43:04.175 FAIL AttributeError: 'str' object has no attribute 'items'

最佳答案

我认为只需要更改创建字典对象。您应该将键和值传递给它。引用链接 BuildIn(create Dictionary)

*** Settings ***
Library RequestsLibrary
Library Collections
Library String

*** Variables ***
${headers} Create Dictionary Authorization=“Bearer abcde”


*** Test Cases ***
Make a simple REST API call
[Tags] API
Create Session my_json http://localhost:3000
Log ${headers}
${response} = Get Request my_json /posts headers=${headers}
Log ${response}
# Check the Response status
Should Be Equal As Strings ${response.status_code} 403
# ${response} = Get Request my_json /posts

${json} = Set Variable ${response.json()}
Log ${json}
Log len(${json})
Should Be Equal As Strings ${json['name']} rajesh

关于python - 在机器人框架中添加授权 header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53692679/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com