Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

I am working on some BTC data analysis and trying to make continuous requests to coinbase API. When running my script, it will always eventually crash on a calls to

r = client.get_spot_price()
r = client.get_buy_price()
r = client.get_sell_price()

The unusual thing is that the script will always crash at different times. Sometimes it will successfully collect data for an hour or so and then crash, other times it will crash after 5 - 10 minutes.

ERROR:

    r = client.get_spot_price()
  File "/home/g/.local/lib/python3.4/site-packages/coinbase/wallet/client.py", line 191, in get_spot_price
    response = self._get('v2', 'prices', 'spot', data=params)
  File "/home/g/.local/lib/python3.4/site-packages/coinbase/wallet/client.py", line 129, in _get
    return self._request('get', *args, **kwargs)
  File "/home/g/.local/lib/python3.4/site-packages/coinbase/wallet/client.py", line 116, in _request
    return self._handle_response(response)
  File "/home/g/.local/lib/python3.4/site-packages/coinbase/wallet/client.py", line 125, in _handle_response
    raise build_api_error(response)
  File "/home/g/.local/lib/python3.4/site-packages/coinbase/wallet/error.py", line 49, in build_api_error
    blob = blob or response.json()
  File "/home/g/.local/lib/python3.4/site-packages/requests/models.py", line 812, in json
    return complexjson.loads(self.text, **kwargs)
  File "/usr/lib/python3.4/json/__init__.py", line 318, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.4/json/decoder.py", line 343, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python3.4/json/decoder.py", line 361, in raw_decode
    raise ValueError(errmsg("Expecting value", s, err.value)) from None
ValueError: Expecting value: line 1 column 1 (char 0)

It seems to be crashing due to some json decoding?

Does anyone have any idea why this will only throw errors at certain times?


I have tried something like the following to avoid crashing due to this error:

#snap is tuple of data containing data from buy, sell , spot price
if not any(snap):                                                                                                 
    print('\n\n-----ENTRY ERROR---- Snap returned None \n\n')                                                     
    success = False                                                                                               
    return 

but it isn't doing the trick

What are some good ways to handle this error in your opinion?


Thanks, any help is much appreciated!

share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.