How to solve HTTPError: 400 Client Error: Bad Request for URL inRobot Frame work
How to solve HTTPError: 400 Client Error: Bad Request for URL inRobot Frame work
我知道有许多类似的问题可用,但其中 none 有效。
谁能告诉我下面的测试用例是否有任何语法错误
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代码和使用的header的截图。现在我不确定如何在我的 python 或机器人框架中获取 HOST header。
如果需要任何其他详细信息,请告诉我。当 get 或 post 请求完成时,我不确定 URL 队列中的 headers
有什么办法可以找出来吗?
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 错误。
有关更多信息,请尝试记录响应内容,它必须向您显示错误消息。
我知道有许多类似的问题可用,但其中 none 有效。 谁能告诉我下面的测试用例是否有任何语法错误
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代码和使用的header的截图。现在我不确定如何在我的 python 或机器人框架中获取 HOST header。 如果需要任何其他详细信息,请告诉我。当 get 或 post 请求完成时,我不确定 URL 队列中的 headers 有什么办法可以找出来吗?
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 错误。
有关更多信息,请尝试记录响应内容,它必须向您显示错误消息。