Post 请求无法在 Robot Framework 中捕获访问令牌
Post Requests Failed to capture the access token in Robot Framework
** Settings ***
Library RequestsLibrary
Library Collections
*** Variables ***
${SERVICE_ROOT} https://xxx.yyy.org/m1/oauth
${SERVICE_NAME} accesstoken
${client_key} 11111111111111111111111111111111111
${client_secret} 2222222222222222222222222222222222222222
*** Test Cases ***
Test 1
Create access token
*** Keywords ***
Create access token
Create Session accessurl ${SERVICE_ROOT} verify=True
&{data_1} Create Dictionary grant_type=client_credentials key=${client_key} secret=${client_secret}
${header} Create Dictionary Content-Type=application/json
${resp} Post Request accessurl /token params=${data_1} headers=${header}
Should be Equal ${resp.status_code} 200
简单来说,我正在尝试将 POST 方法从 Postman 复制到 Robot Framework(类型 oauth 2)
强制参数是 grant type、client id 和 secret。
预期授权:具有访问令牌的持有者
执行后,我得到 401 和 params returns Empty我已经尝试了所有可能的方法来通过更改代码来生成令牌,但都被证明是不成功的。请帮我解决这个问题,让我知道我犯了什么错误,
我对自动化脚本很陌生。
解法:
参考How to generate oauth 2.0 token using "Create Client Oauth2 Session" keyword in robot framework
以上方法有效。
** Settings ***
Library RequestsLibrary
Library Collections
*** Variables ***
${SERVICE_ROOT} https://xxx.yyy.org/m1/oauth
${SERVICE_NAME} accesstoken
${client_key} 11111111111111111111111111111111111
${client_secret} 2222222222222222222222222222222222222222
*** Test Cases ***
Test 1
Create access token
*** Keywords ***
Create access token
Create Session accessurl ${SERVICE_ROOT} verify=True
&{data_1} Create Dictionary grant_type=client_credentials key=${client_key} secret=${client_secret}
${header} Create Dictionary Content-Type=application/json
${resp} Post Request accessurl /token params=${data_1} headers=${header}
Should be Equal ${resp.status_code} 200
简单来说,我正在尝试将 POST 方法从 Postman 复制到 Robot Framework(类型 oauth 2) 强制参数是 grant type、client id 和 secret。 预期授权:具有访问令牌的持有者
执行后,我得到 401 和 params returns Empty我已经尝试了所有可能的方法来通过更改代码来生成令牌,但都被证明是不成功的。请帮我解决这个问题,让我知道我犯了什么错误, 我对自动化脚本很陌生。
解法:
参考How to generate oauth 2.0 token using "Create Client Oauth2 Session" keyword in robot framework
以上方法有效。