api - 如何解决 HTTPError: 400 Client Error: Bad Request for URL inRobot Frame work
问题描述
我知道有许多类似的问题可用,但没有一个有效。有人可以告诉我下面的测试用例是否有任何语法错误
Create Token
Create Session testsession ${baseUrl} verify=true
${body}= create dictionary clientId=unittest.cc.client clientSecret=RyDQ$xxxxxRtv
${header}= create dictionary Content-Type=application/json
${resp}= POST On Session testsession ${reqUri} json=${body} headers=${header} params=${ApiKeyParameter}
${source data}= Evaluate json.loads("""${resp.content}""") json
${token}= Set Variable ${source data['accessToken']}
#No errors Uptill this much - Bearer token creation was successful after that getting error while using it
${header}= create dictionary Authorization=${tpre} ${token} Content-Type=application/json cookies=ss-id=KF84fFy4txxxxxxxxx76i; ss-pid=StDTDxxxxxxxxxxxxn7r
${body}= get file API/data.txt
log to console ${header}
${resp}= post on session testsession /orders json=${body} headers=${header}
log to console ${resp.status_code}
问题是每次我运行测试时都会收到 400 错误。下面是 POSTMAN 提供的 Python 代码和使用的标头的屏幕截图。现在我不确定如何在我的 python 或机器人框架中获取HOST标头。如果需要任何其他详细信息,请告诉我。在完成获取或发布请求时,我不确定 URL 格式中的标题有没有办法找出来?
import requests
import JSON
url = "https://domain:10001/orders?format=json"
payload = json.dumps({ Can ignore this part
})
headers = {
'Authorization': 'Bearer xxx',
'Content-Type': 'application/json',
'Cookie': 'ss-id=xxx; ss-pid=xxx'
}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)
解决方案
如果你们都遇到过此类问题,请不要忘记检查您发送的 JSON / XML 的正文。我的解决了,因为我将转储 JSON 保存在文本文件中,所以在从文件中读取时,我的代码在前面添加了一些额外的空格,所以我收到了 400 错误。
有关更多信息,请尝试记录响应内容,它必须向您显示错误消息。
推荐阅读
- video - ffmpeg 中显示的 FPS 与总帧数/持续时间不匹配
- r - 添加箭头符号以绘制标签 unicode - R
- python - Python / pcolormesh:TypeError:C(24、4)的尺寸与X(24)和/或Y(24)不兼容
- sql - 返回按非唯一属性排序前后的 X 个元素 SQL
- swift - 如何在用户库或相机中获取所选照片的 URL?
- r - 如何将 R 从 3.x 更新到 4.x,我应该吗?
- c++ - C++ 无法解决我的问题。我有控制台错误
- c# - 将参数传递给 PostgreSQL 中的 Insert 语句
- javascript - 让 div 在点击外部时隐藏
- java - 类和对象,通过输入将旧值与新值相加,并将值传递给另一个对象~