python - POST 请求使用 pydev Eclipse 获取 400 错误代码,但在 Postman 上工作

标签 python eclipse api request postman

我正在尝试调用一个在 Postman 上运行的发布请求,但我的代码返回 400。以下是我的尝试:

url = "http://192.168.9.194:7780/xtv-ws-client/api/login/auth? 
accountid=342&password=3534"
headers = {"Content-Type": "application/x-www-form-urlencoded"}
rsp = requests.post(url, headers=headers)
print (rsp.status_code)

url = "http://192.168.9.194:7780/xtv-ws-client/api/login/auth"
Body1 = {
    "accountid": "342",
    "password": "3534"
}
headers = {"Content-Type": "application/x-www-form-urlencoded"}
rsp = requests.post(url, json=Body1, headers=headers)
print (rsp.status_code)

params = {'accountid': '342', 'password': '3534'}
url = "http://192.168.9.194:7780/xtv-ws-client/api/login/auth? 
accountid=342&password=3534"
headers = {"Content-Type": "application/x-www-form-urlencoded"}
rsp = requests.post(url, headers=headers, params = params)
print (rsp.status_code)

这是我的 postman 请求: enter image description here

最佳答案

params = {'accountid': '342', 'password': '3534'}
url = "http://192.168.9.194:7780/xtv-ws-client/api/login/auth"
rsp = requests.post(url, data=params)
print (rsp.status_code)

关于python - POST 请求使用 pydev Eclipse 获取 400 错误代码,但在 Postman 上工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51088698/

相关文章:

python - 字符串日期至今( Pandas )

python - 在python中,如果一个函数没有return语句,它会返回什么?

eclipse - java.lang.IllegalArgumentException : The servlets named [X] and [Y] are both mapped to the url-pattern [/CreationClient] which is not permitted

java - 无法编译 Java + Play! 'play eclipse' 上的框架项目

api - 如何从集合中获取api返回的数据?

python - 如何从 API 中确定 REST API 需要哪些字段?

java - 项目中使用的设计模式

java - 在 Spring Boot Eclipse 中使用多个外部 JAR

ios - 无需等待 API 响应即可更改图标状态。 (标记为最喜欢的功能)

java - 如何通过 JSON API 实现复杂的条件批量部分更新?