jeudi 23 juin 2016
Coinbase Wallet API python Authentication Error, Invalid Signature
Python 3.4 Coinbase Wallet API V2
I have been stuck for some time trying to figure out while this buy call
(and other api calls like get_payment_methods() and get_accounts() ) run into authentication errors. I have successfully been able to run some of these api calls alone in a separate file.
What Does Not Work:
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)
I have triple checked my accounts, keys and secrets and have also tried hard coding them inside the class definition instead of using init members.
What Works:
from coinbase.wallet.client import Client
client = Client(<api_key>, <api_secret>)
buy = client.buy('zzzzzzzz', amount='1', currency="USD", payment_method='aaaaaaaaaa')
The error is as follows:
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
Im thinking that the problem may be due to the use of the API buy method inside of a definition of a class file, that is my api_call.py class.I think this because I can call the buy method ( and others ) just fine from separate files and even outside of the class indentations inside of api_call.py.
Does anyone have any idea why this would raise an Authentication Error? I have looked around in error.py, but haven't yet found a clue on why this might be happening.
As always, any help or thoughts regarding the matter is much appreciated!
EDIT
After running the working and non working code on the same file, *I was successfully able to make both buys. Apparently any POSTs to the API using those member variables, and any instances of client made with member variables wont be authenticated (i.e. self.CB_key ... ).
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)
Inscription à :
Publier les commentaires (Atom)
Aucun commentaire:
Enregistrer un commentaire