whittlem / pycryptobot

Python Crypto Bot (PyCryptoBot)
Apache License 2.0
1.96k stars 739 forks source link

Authenication Coinbase #278

Closed Bandit253 closed 2 years ago

Bandit253 commented 3 years ago

After starting the bot I get this... TypeError: Unicode-objects must be encoded before hashing seems to be in the creation of the signature

Steps to reproduce the behavior:

  1. Configured the config
  2. Run bot with CB config
  3. See error

Expected behavior Should print message block describing config, then continue

I have ensured these, API_Key, API_Secret, API_PASS work with a very slightly different version of class CBProAuth(AuthBase):

I had started my own project before finding this excellent project. I found that the example ode offered on the API docs does not work 'as-is' I have confirmed the Binance interface is working just fine

This is my version, that works

`class CBProAuth(AuthBase):
    # Provided by CBPro: https://docs.pro.coinbase.com/#signing-a-message
    def __init__(self, api_key, secret_key, passphrase):
        self.api_key = api_key
        self.secret_key = secret_key
        self.passphrase = passphrase

    def __call__(self, request):
        timestamp = str(time.time())
        message = ''.join([timestamp, request.method, request.path_url, (request.body or '')])
        request.headers.update(get_auth_headers(timestamp, message,
                                                self.api_key,
                                                self.secret_key,
                                                self.passphrase))
        return request

def get_auth_headers(timestamp, message, api_key, secret_key, passphrase):
    message = message.encode('ascii')
    hmac_key = base64.b64decode(secret_key)
    signature = hmac.new(hmac_key, message, hashlib.sha256)
    signature_b64 = base64.b64encode(signature.digest()).decode('utf-8')
    return {
        'Content-Type': 'Application/JSON',
        'CB-ACCESS-SIGN': signature_b64,
        'CB-ACCESS-TIMESTAMP': timestamp,
        'CB-ACCESS-KEY': api_key,
        'CB-ACCESS-PASSPHRASE': passphrase
    }`
whittlem commented 3 years ago

I'm not aware of anyone else having this issue but I'll take a look.

Can you please answer the following?

  1. What platform are you running on the bots on?
  2. This issue is related to Coinbase Pro only right?
  3. Is this a constant or intermittent issue?
Bandit253 commented 3 years ago

It does seem odd it's just me.

Window 10 Yes, Binance works fine I first experienced the issue using the example code off the Coinbase pro API site, then I found the supplied code and that worked. Then I found this project and the problem returned. Is that intermittent? I could change this code but I really want to divert from this code base. Thanks for a excellent project.

lazydroid commented 3 years ago

@Bandit253 could you please tell your python version as well? Thanks!

Bandit253 commented 3 years ago

No problem @lazydroid

Python 3.9.4 - 64 bit

lazydroid commented 3 years ago

thanks! could you please provide the minimum changes that differ between the current code base and the one that works for you?

(I don't have access to coinbase to check, please, be precise =)

Bandit253 commented 3 years ago

yes that is the straight copy of what works - that security stuff does my head in - I'm not going to be changing any of it.

Thanks for making the change

whittlem commented 2 years ago

Is this resolved?