resy / coinbase_python3

Unofficial Coinbase Python3 Client Library
126 stars 43 forks source link

requests.exceptions.InvalidHeader: Value for header {ACCESS_NONCE: 1609705740747573} must be of type str or bytes, not <class 'int'> #7

Open MichaelOhn opened 3 years ago

MichaelOhn commented 3 years ago

Hi,

After following the installation step from your readme file and trying to execute the following code:

import coinbase

coinbase_api_key    = str('<api_key>')
coinbase_api_secret = str('<api_secret_key>')
coinbase = coinbase.Coinbase.with_api_key(coinbase_api_key, coinbase_api_secret)
balance = coinbase.get_balance()
print('Balance is ' + balance + ' BTC')

I get the following exception:

python3 wallet-watcher.py Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/requests/utils.py", line 868, in check_header_validity
    if not pat.match(value):
TypeError: expected string or bytes-like object

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "wallet-watcher.py", line 7, in <module>
    balance = coinbase.get_balance()
  File "/usr/local/lib/python3.6/dist-packages/coinbase/__init__.py", line 138, in get_balance
    return self.get('/account/balance')['amount']
  File "/usr/local/lib/python3.6/dist-packages/coinbase/__init__.py", line 122, in get
    return self.__rpc.request('GET', path, params)
  File "/usr/local/lib/python3.6/dist-packages/coinbase/CoinbaseRPC.py", line 75, in request
    request = requests.get(url, headers=headers)
  File "/usr/lib/python3/dist-packages/requests/api.py", line 72, in get
    return request('get', url, params=params, **kwargs)
  File "/usr/lib/python3/dist-packages/requests/api.py", line 58, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/lib/python3/dist-packages/requests/sessions.py", line 506, in request
    prep = self.prepare_request(req)
  File "/usr/lib/python3/dist-packages/requests/sessions.py", line 449, in prepare_request
    hooks=merge_hooks(request.hooks, self.hooks),
  File "/usr/lib/python3/dist-packages/requests/models.py", line 306, in prepare
    self.prepare_headers(headers)
  File "/usr/lib/python3/dist-packages/requests/models.py", line 440, in prepare_headers
    check_header_validity(header)
  File "/usr/lib/python3/dist-packages/requests/utils.py", line 872, in check_header_validity
    "bytes, not %s" % (name, value, type(value)))
requests.exceptions.InvalidHeader: Value for header {ACCESS_NONCE: 1609705740747573} must be of type str or bytes, not <class 'int'>

System info:

Kernel: 4.19.25-041925-generic x86_64
bits: 64
Desktop: Gnome 3.28.4
Distro: Ubuntu 18.04.5 LTS

Could I have any advice of what I would be doing wrong ?

Best regards,

Mike O.

n3trob3 commented 3 years ago

This is so true i just tried it now and i am getting the same error, can't i use the requests library directly

theresnotime commented 3 years ago

Per https://github.com/psf/requests/issues/4333#issuecomment-335677895, the python library Requests "tightened its interface to only allow header values to be strings".

An older version of Requests (e.g. 2.3.0) works, but I wouldn't recommend using it :-/

EDIT: See https://github.com/resy/coinbase_python3/compare/master...IAmADoctorYes:patch-1 for a working patch

ohbob commented 3 years ago

Per psf/requests#4333 (comment), the python library Requests "tightened its interface to only allow header values to be strings".

An older version of Requests (e.g. 2.3.0) works, but I wouldn't recommend using it :-/

EDIT: See master...IAmADoctorYes:patch-1 for a working patch

that would not help.

for header in headers.items():
AttributeError: 'str' object has no attribute 'items'
kyledufrane commented 2 years ago

was there ever a resolution?

stenio123 commented 2 years ago

No, this code is for the older API, it doesn't take into account new auth requirements documented here. If you go to the PR referenced above and check the conversation you will see some discussion that even with that fix it wont work. Someone needs to update this to the new API :-(