1

I am unsure why my code isn't working. I have used the same code for months now and am getting an odd error all of a sudden. Not really sure how to troubleshoot what's going wrong. The excel sheet I'm reading is basically a list of ticker names going down the first column like:

VNDA
VNDA
CKPT
SNSE
CNST

My Code:

import matplotlib
matplotlib.use('Agg')
from matplotlib import pyplot as plt
import xlsxwriter as xl
import numpy as np
import yfinance as yf
import pandas as pd 
import mplfinance as mpf 
import pandas_datareader 
from pandas_datareader import data as pdr
yf.pdr_override()
import numpy as np

Individualreport = "C:\\Users\\Ashley\\FromPython.xlsx"

READ = "C:\\Users\\Ashley\\Biotech Data Center 8.1.xlsx"

Ticklist = pd.read_excel(READ,sheet_name='Tickers', header=None)
stocks = Ticklist.values.ravel()

short_sma = 20
mid_sma = 50
long_sma = 100

writer = pd.ExcelWriter(Individualreport, engine='xlsxwriter')

for i in stocks:
    plotdata = pdr.get_data_yahoo(i, start='2020-08-01', end='2021-07-31')
    df = pd.DataFrame(plotdata)

    graph = mpf.plot(df, type = 'candlestick',figratio=(16.7,6),  
         mav=(short_sma,mid_sma,long_sma),
         volume=True, title= str(i), 
         style='default', savefig=dict(fname=''+str(i)+'.png', bbox_inches= "tight"))
    
writer.save()    

Error Code:

PS C:\users\ashley\appdata\roaming\python\python38\site-packages> & C:/Users/Ashley/AppData/Local/Programs/Python/Python39/python.exe "c:/Users/Ashley/OneDrive/Documents/just graphs part 2.py"
Exception in thread Thread-1:
Traceback (most recent call last):
  File "C:\Users\Ashley\AppData\Local\Programs\Python\Python39\lib\threading.py", line 954, in _bootstrap_inner
    self.run()
  File "C:\Users\Ashley\AppData\Local\Programs\Python\Python39\lib\threading.py", line 892, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Users\Ashley\AppData\Local\Programs\Python\Python39\lib\site-packages\multitasking\__init__.py", line 102, in _run_via_pool
    return callee(*args, **kwargs)
  File "C:\Users\Ashley\AppData\Local\Programs\Python\Python39\lib\site-packages\yfinance\multi.py", line 167, in _download_one_threaded
    data = _download_one(ticker, start, end, auto_adjust, back_adjust,
  File "C:\Users\Ashley\AppData\Local\Programs\Python\Python39\lib\site-packages\yfinance\multi.py", line 179, in _download_one
    return Ticker(ticker).history(period=period, interval=interval,
  File "C:\Users\Ashley\AppData\Local\Programs\Python\Python39\lib\site-packages\yfinance\base.py", line 157, in history
    data = data.json()
  File "C:\Users\Ashley\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\models.py", line 900, in json
    return complexjson.loads(self.text, **kwargs)
  File "C:\Users\Ashley\AppData\Local\Programs\Python\Python39\lib\json\__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "C:\Users\Ashley\AppData\Local\Programs\Python\Python39\lib\json\decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Users\Ashley\AppData\Local\Programs\Python\Python39\lib\json\decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
Ashley Adams
  • 95
  • 1
  • 12
  • If you look closely at the Traceback, you'll see this is happening inside `yfinance`, which, in your code, is most likely being called from `pdr.get_data_yahoo()`. I tried using yfinance the other day and got the exact same error (`raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)`). Not sure why the json decoder is having problems inside yfinance. At the time I saw this error I guessed maybe it had something to do with the marker being closed at the time, but ideally that should not make a difference. – Daniel Goldfarb Aug 01 '21 at 19:56
  • https://stackoverflow.com/questions/68331065/json-decode-error-with-yfinance-jsondecodeerror-expecting-value-line-1-column – Daniel Goldfarb Aug 01 '21 at 19:58
  • TRY THIS: https://stackoverflow.com/a/68445570/1639359 – Daniel Goldfarb Aug 01 '21 at 20:01

1 Answers1

2

This should fix your problem

pip uninstall yfinance
pip uninstall pandas-datareader
pip install yfinance --upgrade --no-cache-dir
pip install pandas-datareader

Note, the --no-cache-dir option is important.

Daniel Goldfarb
  • 6,937
  • 5
  • 29
  • 61