quantstats icon indicating copy to clipboard operation
quantstats copied to clipboard

JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Open MrMarc21 opened this issue 4 years ago • 2 comments

Traceback:

JSONDecodeError Traceback (most recent call last) in 6 7 # fetch the daily returns for a stock ----> 8 stock = qs.utils.download_returns('FB') 9 10 # show sharpe ratio

~/.local/lib/python3.6/site-packages/quantstats/utils.py in download_returns(ticker, period) 235 else: 236 p = {"period": period} --> 237 return _yf.Ticker(ticker).history(**p)['Close'].pct_change() 238 239

~/.local/lib/python3.6/site-packages/yfinance/base.py in history(self, period, interval, start, end, prepost, actions, auto_adjust, back_adjust, proxy, rounding, tz, **kwargs) 155 "Our engineers are working quickly to resolve " 156 "the issue. Thank you for your patience.") --> 157 data = data.json() 158 159 # Work with errors

~/.local/lib/python3.6/site-packages/requests/models.py in json(self, **kwargs) 898 # used. 899 pass --> 900 return complexjson.loads(self.text, **kwargs) 901 902 @property

/usr/lib/python3/dist-packages/simplejson/init.py in loads(s, encoding, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, use_decimal, **kw) 516 parse_constant is None and object_pairs_hook is None 517 and not use_decimal and not kw): --> 518 return _default_decoder.decode(s) 519 if cls is None: 520 cls = JSONDecoder

/usr/lib/python3/dist-packages/simplejson/decoder.py in decode(self, s, _w, _PY3) 368 if _PY3 and isinstance(s, binary_type): 369 s = s.decode(self.encoding) --> 370 obj, end = self.raw_decode(s) 371 end = _w(s, end).end() 372 if end != len(s):

/usr/lib/python3/dist-packages/simplejson/decoder.py in raw_decode(self, s, idx, _w, _PY3) 398 elif ord0 == 0xef and s[idx:idx + 3] == '\xef\xbb\xbf': 399 idx += 3 --> 400 return self.scan_once(s, idx=_w(s, idx).end())

JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Code: (https://github.com/ranaroussi/quantstats)

The problem I found yesterday, last week it was working charmingly.

MrMarc21 avatar Jul 16 '21 09:07 MrMarc21

Hello I have a similar issue, with version 0.0.34

qs.plots.returns(data, "SPY")

~/miniconda3/envs/py3/lib/python3.8/site-packages/quantstats/_plotting/wrappers.py in returns(returns, benchmark, grayscale, figsize, fontname, lw, match_volatility, compound, cumulative, resample, ylabel, subtitle, savefig, show)
    264 
    265     returns = _utils._prepare_returns(returns)
--> 266     benchmark = _utils._prepare_benchmark(benchmark, returns.index)
    267 
    268     fig = _core.plot_timeseries(returns, benchmark, title,

~/miniconda3/envs/py3/lib/python3.8/site-packages/quantstats/utils.py in _prepare_benchmark(benchmark, period, rf)
    249 
    250     if isinstance(benchmark, str):
--> 251         benchmark = download_returns(benchmark)
    252 
    253     elif isinstance(benchmark, _pd.DataFrame):

~/miniconda3/envs/py3/lib/python3.8/site-packages/quantstats/utils.py in download_returns(ticker, period)
    235     else:
    236         p = {"period": period}
--> 237     return _yf.Ticker(ticker).history(**p)['Close'].pct_change()
    238 
    239 

~/miniconda3/envs/py3/lib/python3.8/site-packages/yfinance/base.py in history(self, period, interval, start, end, prepost, actions, auto_adjust, back_adjust, proxy, rounding, tz, **kwargs)
    154                                "Our engineers are working quickly to resolve "
    155                                "the issue. Thank you for your patience.")
--> 156         data = data.json()
    157 
    158         # Work with errors

~/miniconda3/envs/py3/lib/python3.8/site-packages/requests/models.py in json(self, **kwargs)
    896                     # used.
    897                     pass
--> 898         return complexjson.loads(self.text, **kwargs)
    899 
    900     @property

~/miniconda3/envs/py3/lib/python3.8/json/__init__.py in loads(s, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
    355             parse_int is None and parse_float is None and
    356             parse_constant is None and object_pairs_hook is None and not kw):
--> 357         return _default_decoder.decode(s)
    358     if cls is None:
    359         cls = JSONDecoder

~/miniconda3/envs/py3/lib/python3.8/json/decoder.py in decode(self, s, _w)
    335 
    336         """
--> 337         obj, end = self.raw_decode(s, idx=_w(s, 0).end())
    338         end = _w(s, end).end()
    339         if end != len(s):

~/miniconda3/envs/py3/lib/python3.8/json/decoder.py in raw_decode(self, s, idx)
    353             obj, end = self.scan_once(s, idx)
    354         except StopIteration as err:
--> 355             raise JSONDecodeError("Expecting value", s, err.value) from None
    356         return obj, end

JSONDecodeError: Expecting value: line 1 column 1 (char 0)

stephanecollot avatar Jul 24 '21 09:07 stephanecollot

It actually comes from yfinance, I had version 0.1.55 I updated to 0.1.63, and now it is working. Maybe we could update requirements it is currently on master: yfinance>=0.1.55

stephanecollot avatar Jul 24 '21 09:07 stephanecollot