首页 > 解决方案 > Python莫霍克错误。返回“异常”消息

问题描述

我一直在使用 Python Mohawk 并不断收到响应 {"error":{"message":"Exception."}}。我最初遇到 API 密钥问题,但通过重新排列 X-Request-Auth 标头解决了这个问题。

下面提供的代码摘要。

from mohawk import Sender
import requests

url = 'https://prod.jdgroupmesh.cloud/stores/jdsportsjx/products/415676/reviews?channel=android-app-tablet'
method = 'GET'

sender = Sender({'id': '850216d081', 'key': '1F13108153574B20866A02BE3D7578E5', 'algorithm': 'sha256'}, url, method, always_hash_content=False, content='', content_type='')
h = sender.request_header.split(", ")
#print(h)
token = h[2] + ", " + h[0] + ", " + h[3] + ", " + h[4]

head = {
'X-NewRelic-ID': 'VQYDUFVWDRABVlVTDwkDU1U=', 
'x-api-key': '1F13108153574B20866A02BE3D7578E5',
'MESH-Commerce-Channel': 'android-app-tablet',
'mesh-version': 'cart=4',
'User-Agent': 'jdsportsjx/6.2.7.8361 (android-app-tablet; Android 7.1.2; Build/NRD90M.G955FXXU1AQJ5)',
'X-Request-Auth': token,
'Host': 'prod.jdgroupmesh.cloud',
'Connection': 'Keep-Alive',
'Accept-Encoding': 'gzip',
}
r = requests.get(url,headers=head)
print(r.text)

标签: pythonpython-3.xhttp

解决方案


推荐阅读