【问题标题】:Python bitstamp api invalid nonce errorPython bitstamp api无效nonce错误
【发布时间】:2014-08-08 17:21:04
【问题描述】:

一个 python 脚本正在运行,但现在没有。

                public_client = bitstamp.client.Public()

                data=backTestBitCoin.getHistoricalPrices();

                trading_client = bitstamp.client.Trading(username='AAA', key='BBB', secret='CCC')
                tick=trading_client.ticker();

                lastBid = float(tick['bid']);
                lastAsk = float(tick['ask']);
                balances = trading_client.account_balance(); #error thrown from this line

我收到以下错误:

                    return self._post("balance/", return_json=True)
                  File "/Library/Python/2.7/site-packages/bitstamp/client.py", line 47, in _post
                    return self._request(requests.post, *args, **kwargs)
                  File "/Library/Python/2.7/site-packages/bitstamp/client.py", line 80, in _request
                    raise BitstampError(error)
                bitstamp.client.BitstampError: Invalid nonce

有人经历过吗?对图书馆不太熟悉,因此不确定是什么原因造成的。

【问题讨论】:

    标签: python bitcoin nonce


    【解决方案1】:

    生成一个新的 api 密钥/秘密解决了这个问题。我相信这是由混合使用 php api 和 python api 或 iphone Bitstamp 应用程序引起的。我会确认这个怀疑,但整体解决方案是拔下电源再重新插入。


    简短的解决方案:我的问题来自使用以下 php 和 python 库,

    php python

    两者都是 A+ 并且易于使用。

    错误是由于他们创建随机数的方法存在以下差异(在我看来两者都不是更“正确”,只是不同)。

    php

                    // generate a nonce as microtime, with as-string handling to avoid problems with 32bits systems
                    $mt = explode(' ', microtime());
                    $req['nonce'] = $mt[1] . substr($mt[0], 2, 6);
                    $req['key'] = $key;
                    $req['signature'] = $this->get_signature($req['nonce']);
    

    蟒蛇

                    self._nonce = max(int(time.time()), nonce)
    

    time.time() 为您提供:1403366728.072785 microtime() 给你:1403366859731819。

    我提出的解决方案是将python代码更改为:

    self._nonce = max(int(time.time()*1000000), nonce),错误就解决了。

    【讨论】:

      猜你喜欢
      • 2019-10-23
      • 2019-12-21
      • 2018-03-16
      • 2018-02-23
      • 2018-03-15
      • 1970-01-01
      • 2021-09-14
      • 2015-04-01
      • 2017-08-22
      相关资源
      最近更新 更多