嗨,这是我的脚本文件。我想从创建的会话中获取访问令牌。我尝试了这种方式,但我获取访问令牌为无。可以帮助我。
Create Session httpbin ${server_URL} verify=${True}
&{dict} Create Dictionary username=${username} password=${password} email=${email} role=${role}
${header} Create Dictionary Content-Type=application/json charset=UTF-8
${resp} Post Request httpbin /api/Owners data=${dict} headers=${header}
${accessToken}= evaluate $resp.json().get("access_token")
Log to Console ${accessToken}
log Many ${resp.text}
${id} Evaluate $resp.json().get("id")
Log ${id}
log to console ${resp.status_code}
${resp} Get Request httpbin uri=/api/Owners?access_token=${accessToken}
${resp} Get Substring ${resp.text} 1 -1
Log ${resp}
${json_str} Convert JSON To String ${resp}
Should Contain ${json_str} ${id}
答案 0 :(得分:0)
使用请求我将尝试登录并创建令牌
import requests
login = {
"user" : "username",
"pass" : "passwrod",
}
这里写你自己的令牌 这只是一个例子
accesToken = {
"Accept" : "application/json",
}
request = requests.post('http://www.web.com/user', data=login, headers=accesToken')