这个错误是由于未授权的访问API导致的,可以尝试以下步骤解决此问题:
确保使用的密钥(API Key)和密钥(Secret Key)是正确的,可以尝试重新生成API Key和Secret Key。
检查你的请求头和参数是否正确,尤其是签名参数(signature)是否正确,该参数为通过SHA256 HMAC散列方法生成的,安全参数timestamp和nonce需要按照要求生成。
以下是样例代码示例:
import hashlib
import hmac
import time
api_key = 'your api key'
secret_key = 'your secret key'
symbol = 'BTCUSDT'
timestamp = int(time.time() * 1000)
query_string = 'symbol=' + symbol + '×tamp=' + str(timestamp)
signature = hmac.new(secret_key.encode('utf-8'), query_string.encode('utf-8'), hashlib.sha256).hexdigest()
headers = {
'X-MBX-APIKEY': api_key,
}
params = {
'symbol': symbol,
'timestamp': timestamp,
'signature': signature
}
response = requests.get('https://api.binance.com/api/v3/allOrders', headers=headers, params=params)
print(response.json())
需要注意的是,以上代码仅供参考,签名过程可能会因Binance API版本或其他原因而略有不同,如需更详细的信息,建议查看官方文档。