python-mercadobitcoin icon indicating copy to clipboard operation
python-mercadobitcoin copied to clipboard

erro no python 3.7

Open romeucampos opened this issue 5 years ago • 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

romeucampos avatar Mar 17 '19 02:03 romeucampos

Can you solved?

FernandoGaspar avatar Jun 29 '19 12:06 FernandoGaspar

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.

guilhermesilvame avatar Aug 11 '19 23:08 guilhermesilvame

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)

lbltavares avatar Sep 14 '20 16:09 lbltavares