Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python 3.4.5 issues #14

Closed
TearsOfTheEarth opened this issue Jul 11, 2017 · 5 comments
Closed

Python 3.4.5 issues #14

TearsOfTheEarth opened this issue Jul 11, 2017 · 5 comments
Assignees

Comments

@TearsOfTheEarth
Copy link

Hi,

Many thanks for your efforts. Not sure what particular python 3 version you tried this with but this does not work with Python 3.4.5 out of the box:

  File "/home/ccxt/ccxt-master/ccxt/__init__.py", line 335, in hmac
    h = hmac.new (secret, request, hash)
  File "/usr/lib64/python3.4/hmac.py", line 144, in new
    return HMAC(key, msg, digestmod)
  File "/usr/lib64/python3.4/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'

Here is a quick fix for this:

--- ccxt-master/ccxt/__init__.py        2017-07-10 05:05:45.000000000 +0300
+++ ccxt-master.bak/ccxt/__init__.py    2017-07-11 22:08:37.627994125 +0300
@@ -157,6 +157,8 @@
         headers.update ({ 'User-Agent': userAgent })
         if self.verbose:
             print (url, method, headers, data)
+        if data:
+            data = data.encode ()
         request = _urllib.Request (url, data, headers)
         request.get_method = lambda: method
         response = None
@@ -332,7 +334,7 @@

     @staticmethod
     def hmac (request, secret, hash = hashlib.sha256, digest = 'hex'):
-        h = hmac.new (secret, request, hash)
+        h = hmac.new (secret.encode(), request.encode(), hash)
         if digest == 'hex':
             return h.hexdigest ()
         elif digest == 'base64':

@TearsOfTheEarth
Copy link
Author

This has been also tested on the latest 3.x stable - 3.6.1.

@kroitor
Copy link
Member

kroitor commented Jul 11, 2017

Thank you for reporting this. Integrating the fix now.

@kroitor
Copy link
Member

kroitor commented Jul 11, 2017

Can you please write how to reproduce this bug (I mean, which exchange you're testing, which method)?

@kroitor kroitor self-assigned this Jul 11, 2017
@TearsOfTheEarth
Copy link
Author

yobit fetch_balance but should be applicable for any exchange and method where API key is required

@kroitor
Copy link
Member

kroitor commented Jul 11, 2017

Fixed it by integrating your diff, thank you very much for help!

kroitor pushed a commit that referenced this issue Nov 1, 2017
kroitor pushed a commit that referenced this issue Mar 11, 2018
Legogris added a commit to Legogris/ccxt that referenced this issue Apr 8, 2019
Explicitly set http(s) agents instead of using deepExtend
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants