【问题标题】:Invalid API Key hmac python无效的 API 密钥 hmac python
【发布时间】:2017-09-15 04:38:17
【问题描述】:

我正在尝试使用https://c-cex.com/ 的 api 为我的投资组合构建比特币交易应用程序,但在使用需要身份验证的私有函数时遇到了问题。它提供了一个如何连接的 php 示例,我尽我所能在 python 中重新创建它,但它返回我的密钥无效(尽管我直接从我的电子邮件中复制了 apikey

apikey='141FA9467F8EAC7917A9D6279AD96B4F';
apisecret='6A946F6A331F8CCDFA19EB2D73FD9B1D';
dt = datetime.datetime.now()
nonce= (dt - datetime.datetime(1970,1,1)).total_seconds()

uri='https://c-cex.com/t/api.html?a=getbalance&currency=BTC&apikey=' + apikey + '&nonce=' + str(nonce);
sign = hmac.new(bytes(apisecret,encoding='utf-8'), uri.encode(encoding='utf-8'), hashlib.sha512).hexdigest()
headers = {'apisign': sign}

response = requests.get(uri,headers)
print(response.json())

返回的输出是

{'result': None, 'success': False, 'message': 'APIKEY_INVALID'}

我能做的最好的假设是我没有正确使用 hmac 函数我已经用 2 个单独的 API 密钥测试了它(我的实际 API 密钥和这个测试代码中的一个只能访问 GET 函数)

【问题讨论】:

    标签: python api hmac


    【解决方案1】:

    我找不到任何答案,所以我查看了一些会做类似事情的开源项目。

     encoding='ASCII'
    

    是答案

    【讨论】:

      猜你喜欢
      • 2022-06-30
      • 2019-01-13
      • 2014-08-15
      • 2019-04-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-01
      相关资源
      最近更新 更多