Home > OS >  Yahoo and pandas-datareader error: RemoteDataError: Unable to read URL
Yahoo and pandas-datareader error: RemoteDataError: Unable to read URL

Time:08-18

I am unable to grab stock data from yahoo finance, even I have done updating pandas and pandas-data reader by commanding pip install --upgrade pandas and pip install --upgrade pandas-datareader on the terminal.

import math
import pandas_datareader as web
import numpy as np
import pandas as pd
from sklearn.preprocessing import MinMaxScaler
from keras.models import Sequential
from keras.layers import Dense, LSTM
import matplotlib.pyplot as plt

df = web.DataReader('APPL', data_source='yahoo', start='2012-01-01', end='2022-08-17')
df

however I am keep receiving this error message:

RemoteDataError: Unable to read URL: https://finance.yahoo.com/quote/APPL/history?period1=1325390400&period2=1660795199&interval=1d&frequency=1d&filter=history

Can anyone help?

CodePudding user response:

There is no stock called APPL. You probably wanted to write AAPL:

df = web.DataReader('AAPL', data_source='yahoo', start='2012-01-01', end='2022-08-17')

CodePudding user response:

I think your ticker or company id is misspelled. Could it be 'AAPL'?

UPDATE

In google colab you need to tune your headers. This works for me there

import requests
import pandas_datareader as web

session = requests.session()
session.headers['User-Agent'] = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36'

df = web.DataReader('AAPL', data_source='yahoo', start='2012-01-01', end='2022-08-17', session=session)
df

There is also a related issue here: https://github.com/pydata/pandas-datareader/issues/923

CodePudding user response:

 pip install --upgrade pandas-datareader

Once you install it you have to delete existing runtime so that what you install come into force.

Follow these steps:

click on Runtime
select Disconnect and delete runtime

it will reset your current runtime and then

click on Runtime
select Run all

Apart from that the ticker you mention is wrong

Incorrect ticker : APPL # you mention this ticker in your code
Correct ticker   : AAPL
  • Related