python 3.4 和 Coinbase V2 API
我正在进行一些 BTC 数据分析,并尝试向 coinbase API 发出持续请求。运行我的脚本时,它最终总是会在调用时崩溃
r = client.get_spot_price()
r = client.get_buy_price()
r = client.get_sell_price()
不同寻常的是,脚本总是会在不同的时间崩溃。有时它会成功收集一个小时左右的数据然后崩溃,有时它会在 5-10 分钟后崩溃。
错误:
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)
由于某些 json 解码,它似乎崩溃了?
有谁知道为什么这只会在某些时候抛出错误?
我尝试了类似以下的方法以避免由于此错误而崩溃:
#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
但它没有起到作用
您认为处理此错误的一些好方法是什么?
谢谢,非常感谢任何帮助!