【发布时间】:2019-08-08 04:12:50
【问题描述】:
我有一个问题...... 我想从我正在玩的游戏的 API 中获得正确的响应,但它不能正常工作。 我已经使用 python 的 requests 库以及 Postman 对其进行了测试。使用 python 它只是无法工作,我不明白为什么。使用 Postman,它在第一次就起作用了......
这是我的python代码:
body = {
"ids":[
"831e8094-581c-4ccc-a6a2-62c887dee9a1" # this is my account id or so, but it doesnt matter if u have it, just test it
],
"appBundle":"com.deemedyainc.duels",
"appVersion":"0.6.6",
"platform":"Android"
}
headers = {
"Expect": "100-continue",
"Content-Type": "application/json",
"X-Unity-Version": "2018.2.14f1",
"Transfer-Encoding": "chunked",
"User-Agent": "Dalvik/2.1.0 (Linux; U; Android 5.1.1; SM-G955N Build/NRD90M)",
"Host": "api-duels-test.galapagosgames.com",
"Connection": "Keep-Alive",
"Accept-Encoding": "gzip"
}
url = "http://api-duels-test.galapagosgames.com/general/login"
response = requests.post(url, headers=headers, json=body)
我得到的响应是 400 Bad Request
我的邮递员请求:
URI 保证相同。 也许这与他们使用 websockets 协议而不是纯 HTML 协议有关?但是为什么它会和 Postman 一起工作呢?我不认为 Postman 也使用 websocket 协议
各位,我需要你们的帮助... :D 谢谢:)
【问题讨论】:
-
作为健全性检查,网址是否相同?在邮递员和代码中?我测试了你的代码,得到了
400 Bad Request -
在邮递员中,可以保存到python。 - 试试吧,它在你的标题中。
-
如果你有邮递员,试试那个,它会工作的......是的,Uri 绝对是一样的
-
@JulianCamilleri rly?我去看看,谢谢!
-
似乎
Transfer-Encoding标头导致了 400 响应;没有它,我能够得到 200 个响应。事实上,您似乎不需要任何这些标题。
标签: python rest api python-requests postman