0
votes

I am having a problem executing this code.

   import datetime as dt
   import matplotlib.pyplot as plt from matplotlib 
   import style import pandas as pd 
   import pandas_datareader.data as web 
   style.use('ggplot') 
   start=dt.datetime(2000,1,1)
   end=dt.datetime(2016,12,31)
   df= web.DataReader('TSLA', 'yahoo', start, end) 
   print(df.head()) 

I am facing this error:

ConnectionError(e, request=request) requests.exceptions.

ConnectionError:

HTTPConnectionPool(host='ichart.finance.yahoo.com', port=80):

Max retries exceeded with url: /table.csv?>s=TSLA&f=2016&g=d&b=1&d=11&e=31&ignore=.csv&c=2000&a=0

(Caused by NewConnectionError(': Failed to establish a new connection: [Errno 11001] getaddrinfo failed',))

2
Are you sure ichart.finance.yahoo.com is the rigth host ? My request gives me a DNS error. - Nab Ilovich
Have you checked if the site is accessible from a browser? I can not access it. It looks like host is wrong - dlmeetei
Thanks a lot! I got it. - KUSHAL AGRAWAL

2 Answers

2
votes

The financial API provided by Yahoo was discontinued. This feature won't be provided anymore :

https://forums.yahoo.net/t5/Yahoo-Finance-help/Is-Yahoo-Finance-API-broken/td-p/250503

1
votes

It was so simple!

replace yahoo with google in code.

running code:

import datetime as dt
import matplotlib.pyplot as plt
from matplotlib import style
import pandas as pd
import pandas_datareader.data as web
import numpy as np
style.use('ggplot')
start=dt.datetime(2000,1,1)
end=dt.datetime(2016,12,31)
df= web.DataReader('ERIE', 'google', start, end)
print(df.head())

But still, this code has a drawback.

  1. this code only works for american based companies and not for indian companies. try yourself!

KUSHAL