alfakini/python-mercadobitcoin

erro no python 3.7

romeucampos opened this issue · 3 comments

C:\Users\Romeupc\GgUzbKZNcKZZiEWbVtSxtNhC44Zh3tX2pfon37\python.exe "C:/Users/Romeupc/PycharmProjects/untitled1/teste mbtc.py"
Traceback (most recent call last):
File "C:/Users/Romeupc/PycharmProjects/untitled1/teste mbtc.py", line 5, in
print(mbtc.list_orders(coin_pair="BRLBTC"))
File "C:\Users\Romeupc\GgUzbKZNcKZZiEUzCE1pZpitdNYTNRLAZacF4eKrUf35f66-packages\mercadobitcoin\trade_api.py", line 74, in list_orders
return self.__check_response(self.__post_tapi("list_orders", kwargs ))
File "C:\Users\Romeupc\GgUzbKZNcKZZiEUzCE1pZpitdNYTNRLAZacF4eKrUf35f66-packages\mercadobitcoin\trade_api.py", line 133, in __post_tapi
"TAPI-MAC": self.__signature(payload)
File "C:\Users\Romeupc\GgUzbKZNcKZZiEUzCE1pZpitdNYTNRLAZacF4eKrUf35f66-packages\mercadobitcoin\trade_api.py", line 141, in __signature
signature = hmac.new(self.secret, digestmod=hashlib.sha512)
File "C:\Users\Romeupc\GgUzbKZNcKZZiEUzCE1pZpitdNYTNRLAZacF4eKrUf35f66.py", line 153, in new
return HMAC(key, msg, digestmod)
File "C:\Users\Romeupc\GgUzbKZNcKZZiEUzCE1pZpitdNYTNRLAZacF4eKrUf35f66.py", line 49, in init
raise TypeError("key: expected bytes or bytearray, but got %r" % type(key).name)
TypeError: key: expected bytes or bytearray, but got 'str'

Process finished with exit code 1

Can you solved?

A possible solution is:

Instead of doing:

mbtc = TradeApi(<API_ID>, <API_SECRET>)

Do this:

mbtc = TradeApi(<API_ID>, bytes(<API_SECRET>, 'latin1'))

Contact the author to fix the source code to work in Python 3.x.

You can also modify the file trade_api.py, line 141:
signature = hmac.new(self.secret, digestmod=hashlib.sha512)
to:
signature = hmac.new(self.secret.encode(), digestmod=hashlib.sha512)