coinbase / coinbase-python

DEPRECATED — Coinbase Python API
Apache License 2.0
524 stars 218 forks source link

Added pagination for GET requests #77

Closed xhockey5 closed 6 years ago

xhockey5 commented 6 years ago

This will collect data from all the pages and return it as 1 data section to the user. This corresponds to the issue brought up here https://github.com/coinbase/coinbase-python/issues/34.

sds commented 6 years ago

Thanks for the pull request, @xhockey5. This fails the existing test suite.

Once the tests are passing will be happy to merge. Thanks!

xhockey5 commented 6 years ago

@sds Can you give me a little more insight into what I should do? When i revert my change I still get a ton of tests that fail and it doesn't appear that my function is in the traceback. I could be doing something wrong, but im just running "make tests" This is an example of code the doesnt seem to use my code (I've only modified the _get function)

ERROR: test_commit (tests.test_model.TestWithdrawal)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/httpretty/core.py", line 1029, in wrapper
    return test(*args, **kw)
  File "/home/chris/repos/myfork/coinbase-python/tests/helpers.py", line 28, in inner
    return fn(*args, **kwargs)
  File "/home/chris/repos/myfork/coinbase-python/tests/test_model.py", line 574, in test_commit
    withdrawal2 = withdrawal.commit()
  File "/home/chris/repos/myfork/coinbase-python/coinbase/wallet/model.py", line 337, in commit
    response = self.api_client._post(self.resource_path, 'commit')
  File "/home/chris/repos/myfork/coinbase-python/coinbase/wallet/client.py", line 154, in _post
    return self._request('post', *args, **kwargs)
  File "/home/chris/repos/myfork/coinbase-python/coinbase/wallet/client.py", line 116, in _request
    response = getattr(self.session, method)(uri, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 535, in post
    return self.request('POST', url, data=data, json=json, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 488, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 609, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/requests/adapters.py", line 497, in send
    raise SSLError(e, request=request)
SSLError: ("bad handshake: SysCallError(32, 'EPIPE')",)
sds commented 6 years ago

Tests pass locally for me on master:

⨠ make tests
nosetests tests
...............................................................................................................................
----------------------------------------------------------------------
Ran 127 tests in 1.843s

OK

With your branch I get:

⨠ make tests
nosetests tests
..........E...........................................................E........................................................
======================================================================
ERROR: test_base_api_uri_used_instead_of_default (tests.test_client.TestClient)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/shanedasilva/.pyenv/versions/2.7.14/lib/python2.7/site-packages/httpretty/core.py", line 1029, in wrapper
    return test(*args, **kw)
  File "/Users/shanedasilva/src/ghc/coinbase/coinbase-python/tests/test_client.py", line 190, in test_base_api_uri_used_instead_of_default
    self.assertEqual(client2._get().status_code, 200)
  File "/Users/shanedasilva/src/ghc/coinbase/coinbase-python/coinbase/wallet/client.py", line 134, in _get
    content = json.loads(resp._content)
  File "/Users/shanedasilva/.pyenv/versions/2.7.14/lib/python2.7/json/__init__.py", line 339, in loads
    return _default_decoder.decode(s)
  File "/Users/shanedasilva/.pyenv/versions/2.7.14/lib/python2.7/json/decoder.py", line 364, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/Users/shanedasilva/.pyenv/versions/2.7.14/lib/python2.7/json/decoder.py", line 382, in raw_decode
    raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded
-------------------- >> begin captured logging << --------------------
urllib3.connectionpool: DEBUG: Starting new HTTP connection (1): example.com
urllib3.connectionpool: DEBUG: http://example.com:80 "GET /api/v1/ HTTP/1.1" 200 0
--------------------- >> end captured logging << ---------------------

======================================================================
ERROR: test_response_handling (tests.test_client.TestClient)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/shanedasilva/.pyenv/versions/2.7.14/lib/python2.7/site-packages/httpretty/core.py", line 1029, in wrapper
    return test(*args, **kw)
  File "/Users/shanedasilva/src/ghc/coinbase/coinbase-python/tests/test_client.py", line 116, in test_response_handling
    response = client._get(str(code))
  File "/Users/shanedasilva/src/ghc/coinbase/coinbase-python/coinbase/wallet/client.py", line 134, in _get
    content = json.loads(resp._content)
  File "/Users/shanedasilva/.pyenv/versions/2.7.14/lib/python2.7/json/__init__.py", line 339, in loads
    return _default_decoder.decode(s)
  File "/Users/shanedasilva/.pyenv/versions/2.7.14/lib/python2.7/json/decoder.py", line 364, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/Users/shanedasilva/.pyenv/versions/2.7.14/lib/python2.7/json/decoder.py", line 382, in raw_decode
    raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded
-------------------- >> begin captured logging << --------------------
urllib3.connectionpool: DEBUG: Starting new HTTPS connection (1): api.coinbase.com
urllib3.connectionpool: DEBUG: https://api.coinbase.com:443 "GET /200 HTTP/1.1" 200 105
urllib3.connectionpool: DEBUG: Resetting dropped connection: api.coinbase.com
urllib3.connectionpool: DEBUG: https://api.coinbase.com:443 "GET /201 HTTP/1.1" 201 105
urllib3.connectionpool: DEBUG: Resetting dropped connection: api.coinbase.com
urllib3.connectionpool: DEBUG: https://api.coinbase.com:443 "GET /204 HTTP/1.1" 204 0
--------------------- >> end captured logging << ---------------------

----------------------------------------------------------------------
Ran 127 tests in 1.641s

FAILED (errors=2)
make: *** [tests] Error 1

I'm not sure how to explain the discrepancy. Did you follow the instructions in the README for running tests?

xhockey5 commented 6 years ago

I thought i did... Ill go through it again and see what I can find, thanks

xhockey5 commented 6 years ago

I just repushed, and the tests are passing now. I dont know why I was getting a ton of errors running "make tests", but when I ran tox the tests passed.

sds commented 6 years ago

Thanks, @xhockey5!