'Failed to obtain stock quotes data from yahoo and shows timeout error (In python)

I try to obtain stock prices by using pandas datareader with the following code in python:

Closeprice = pd.DataFrame()
tickers = ['AAPL','TSM','COKE','V','GE','JNJ','T','BABA']
for i in tickers:
    tmp = pdr.DataReader(i, 'yahoo', '1/1/2010', dt.date.today())
    Closeprice[i] = tmp['Adj Close']

However. it shows timeout error:

ReadTimeout: HTTPSConnectionPool(host='finance.yahoo.com', port=443): Read timed out. (read timeout=30)

Is it because of the yahoo side of the problem or anything else might be causing the issue ? Thanks.



Solution 1:[1]

import pandas_datareader.data as web
import pandas as pd

Closeprice = pd.DataFrame()
tickers = ['AAPL','TSM','COKE','V','GE','JNJ','T']
for i in tickers:
    print(i)
    tmp = web.DataReader(i, 'yahoo', start='2010-05-15', end='2010-05-20')
    Closeprice[i] = tmp['Adj Close']
    print(tmp.columns)
    print(Closeprice[i])

An error occurs when calling 'BABA', so I removed it. I also changed the code. However, I checked your code also works.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1