Open philipperemy opened 7 years ago
Because I'm having this error:
c = 'hello'
k = 'k'
s = 's'
pprint(api.account_balance(c, k, s))
Traceback (most recent call last):
File "/Users/philipperemy/PycharmProjects/bitstamp/hello.py", line 19, in <module>
pprint(api.account_balance(c, k, s))
File "/Users/philipperemy/venv/lib/python3.6/site-packages/bitstampy/api.py", line 40, in account_balance
calls.APIAccountBalanceCall(client_id, api_key, api_secret)
File "/Users/philipperemy/venv/lib/python3.6/site-packages/bitstampy/calls.py", line 81, in call
self.api_secret, msg=message, digestmod=hashlib.sha256)
File "/Users/philipperemy/venv/lib/python3.6/hmac.py", line 144, in new
return HMAC(key, msg, digestmod)
File "/Users/philipperemy/venv/lib/python3.6/hmac.py", line 42, in __init__
raise TypeError("key: expected bytes or bytearray, but got %r" % type(key).__name__)
TypeError: key: expected bytes or bytearray, but got 'str'
Can you please advice? Thanks!
In calls.py
:
def call(self, **params):
nonce = self._get_nonce()
message = nonce + self.client_id + self.api_key
signature = hmac.new(bytes(self.api_secret.encode('utf8')),
msg=bytes(message.encode('utf8')),
digestmod=hashlib.sha256)
signature = signature.hexdigest().upper()
params.update({
'key': self.api_key, 'signature': signature, 'nonce': nonce
})
return super(APIPrivateCall, self).call(**params)
Just for information I changed this function and it works. Not confident if it would work for python2 so I prefer to ask you before sending a PR.
Thanks
Worked fine on 3 for me so far. Perhaps it was a function specific bug.
@philipperemy what exactly did you change? Was it a problem with sending the output to pprint
? If it's small, might be easiest to submit as a change and I can have a look.
@unwitting I converted the arguments from str to bytes when calling hmac.new
.
self.api_secret
to bytes(self.api_secret.encode('utf8'))
message
to bytes(message.encode('utf8'))
Seems OK :) send an MR?
Encountered the same problem on python 3.6
Would somebody be able to try the code in https://github.com/unwitting/bitstampy/issues/11#issuecomment-322133630 locally and submit as an MR if it's good please?
Does this library support python3?