【发布时间】:2020-11-14 10:09:46
【问题描述】:
我正试图找出一个奇怪的问题。我有工作 python 代码,我想翻译成 NodeJS。 Python 代码非常简单且有效:
import requests
LOGIN_URL = 'https://android.clients.google.com/auth'
params = {'Email': '***', 'EncryptedPasswd': b'***', 'service': 'androidmarket', 'accountType': 'HOSTED_OR_GOOGLE', 'has_permission': 1, 'source': 'android', 'device_country': 'us', 'lang': 'us'}
response = requests.post(LOGIN_URL, data=params, verify=True)
print(response.text)
这是 NodeJS 版本代码:
const request = require('request');
const LOGIN_URL = 'https://android.clients.google.com/auth'
const params = {'Email': '***', 'EncryptedPasswd': '***', 'service': 'androidmarket', 'accountType': 'HOSTED_OR_GOOGLE', 'has_permission': 1, 'source': 'android', 'device_country': 'us', 'lang': 'us'}
request({url: LOGIN_URL, method: 'POST', form: params}, function(error, response) {
console.log(response.statusCode);
});
这不起作用,我正在返回 403 - 错误请求。 我尝试将协议更改为 http,然后在 Wireshark 中检查数据包内容。它们几乎相同,只是略有不同。我尝试通过覆盖 NodeJS 版本中的标头来消除所有差异,但没有帮助。所以我的猜测是https有问题?
我错过了什么? Python 和 NodeJS 之间可能有什么区别?
【问题讨论】:
-
在两个代码中都使用 url httpbin.org/post,然后你会返回(作为 JSON 数据)所有听众、cookie 等发送到这个 url - 然后你可以比较 Python 和 NodeJS 的结果。跨度>
-
最终使用一些本地代理服务器,如 Charles Proxy 或 Man-In-The-Middle Proxy(在 Python 中创建)并在两个连接中使用它们来查看所有发送到服务器的数据 - 然后你可以比较它们。跨度>
-
@furas 我已经通过 Wireshark 测试了 HTTP 请求内容,并且能够为 Python 和 NodeJS 实现相同的内容。
-
@momo 但这似乎没有任何区别。当我在 Wireshark 的 http 请求中看到这一点时,它们是相同的,因为
EncryptedPasswd作为字符串发送。