python-2.7 - 如何使用机器人测试框架从创建的会话中获取访问令牌
问题描述
嗨,这是我的脚本文件。我想从创建的会话中获取访问令牌。我尝试过这种方式,但我得到的访问令牌没有。任何帮助我。
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}
解决方案
使用请求我将尝试登录并创建一个令牌
import requests
login = {
"user" : "username",
"pass" : "passwrod",
}
这里写你自己的令牌,这只是一个例子
accesToken = {
"Accept" : "application/json",
}
request = requests.post('http://www.web.com/user', data=login, headers=accesToken')
推荐阅读
- c# - 请求路径与支持的文件类型不匹配
- sql-server - 如何按用户汇总设备工单小时数
- google-chrome - 在谷歌浏览器中将 --user-data-dir 设置为空字符串时会发生什么?
- python - 在python中将数字存储在多维(稀疏)数组中的最佳方法
- vue.js - 如何为 Vue Apollo 导入 Apollo Client 3?
- c# - 以相反的顺序显示二维数组的行
- flutter - 在颤动中将二进制数据转换为音频
- azure - 如何在 Azure 中将 pdf 转换为 base64
- android - 从表单中提取数据以登录 Android 应用程序
- javascript - useEffect 持续触发 GET 请求