Coinbase Wallet API python身份验证错误,签名无效

时间:2016-06-22 22:17:30

标签: python authentication coinbase-api

Python 3.4 Coinbase Wallet API V2

我已经被困了一段时间试图找出这个买入电话 (以及其他api调用,如get_payment_methods()和get_accounts())会遇到身份验证错误。我已经成功地在一个单独的文件中单独运行了一些api调用。

什么不起作用

class api_call(object):                                                                                                           

      def __init__(self):                                                                                                           
          self.CB_key = xxxxxxxx                                                                                                        
          self.CB_secret = yyyyyyyy                                                                                                    
          self.CB_account = zzzzzzzzz                                                                                                    
          self.CB_payment_method = aaaaaaaaaa

      def buy_c(self, exchange, b_amount):                                                                                
          client = Client(self.CB_key, self.CB_secret)                                                                          
          buy = client.buy(self.CB_account, amount=str(b_amount), currency="USD", payment_method=self.CB_payment_method)

api = api_call()
buy = api.buy('COIN-BS', 1)

我已经对我的帐户,密钥和密码进行了三次检查,并且还尝试在类定义中对其进行硬编码,而不是使用 init 成员。

有效:

 from coinbase.wallet.client import Client
 client = Client(<api_key>, <api_secret>)

 buy = client.buy('zzzzzzzz', amount='1', currency="USD", payment_method='aaaaaaaaaa')

错误如下:

Traceback (most recent call last):
File "api_call.py", line 126, in <module>
   buy = api.buy('COIN-BS', 1)
File "api_call.py", line 110, in buy
   buy = client.buy_c( self.CB_account, amount=str(amount), currency="USD", payment_method="XXXXXXXXXXXX")
File "/home/LA/.local/lib/python3.4/site-packages/coinbase/wallet/client.py", line 381, in buy
   response = self._post('v2', 'accounts', account_id, 'buys', data=params)
File "/home/LA/.local/lib/python3.4/site-packages/coinbase/wallet/client.py", line 132, in _post
   return self._request('post', *args, **kwargs)
File "/home/LA/.local/lib/python3.4/site-packages/coinbase/wallet/client.py", line 116, in _request
   return self._handle_response(response)
File "/home/LA/.local/lib/python3.4/site-packages/coinbase/wallet/client.py", line 125, in _handle_response
   raise build_api_error(response)

coinbase.wallet.error.AuthenticationError: APIError(id=authentication_error): invalid signature

我认为问题可能是由于在类文件的定义中使用API​​购买方法,即我的api_call.py类。我认为这是因为我可以调用buy方法(和其他方法)从单独的文件中提取,甚至在api_call.py内的类缩进之外。

有谁知道为什么会引发身份验证错误?我在error.py环顾四周,但还没有找到为什么会发生这种情况的线索。

与往常一样,对此事的任何帮助或想法都非常感谢!

修改

在同一个文件上运行工作和非工作代码后,我成功地完成了两次购买。在尝试了其他一些事情后,我发现使用那些全局修改的变量,命令行参数和更新的对象成员变量显然对API的任何POST都会产生此身份验证错误。这应该发生吗?

from coinbase.wallet.client import Client

#Globals
key = 'xxxxxx'
secret = 'yyyyyy'
account = 'zzzzzzz'
payment = 'aaaaaaa'

class api_call(object):                                                                                                           

  def __init__(self):                                                                                                           
      self.CB_key = None                                                                                                        
      self.CB_secret = None                                                                                                    
      self.CB_account = None                                                                                                    
      self.CB_payment_method = None

  def buy_c(self, exchange, b_amount):                                                                                
      client = Client(key, secret)                                                                          
      buy = client.buy(account, amount=str(b_amount), currency="USD", payment_method=payment)

client = Client(key, secret)
buy = client.buy(account, amount='1', currency="USD", payment_method=payment)

api = api_call()
buy = api.buy_c('COIN-BS', 1)

1 个答案:

答案 0 :(得分:0)

经过广泛的静态分析后,我得出结论,这可能是你的问题。

buy = api.buy('COIN-BS', 1) -> buy = api.buy_c('COIN-BS', 1)

还要弄清楚为什么您的堆栈跟踪有client.buy_c而不是client.buy