0

I am trying to download historical stock prices of AAPL from yahoo query but failed. I am very new to python and do not know which method to apply in auto extracting the designated link into my desired local directory.

pullData("AAPL") with result: AAPL https://query1.finance.yahoo.com/v7/finance/download/AAPL?period1=345398400&period2=1505577600&interval=1d&events=history&crumb=X44gAJPyoNu main loop HTTP Error 401: Unauthorized

import urllib2
import time
import csv
import requests
import pandas as pd

def pullData(stock):
    try:
        print stock
        url = 'https://query1.finance.yahoo.com/v7/finance/download/'+stock+'?period1=345398400&period2=1505577600&interval=1d&events=history&crumb=X44gAJPyoNu'
        print url

        response = urllib2.urlopen(url)
        html = response.read()


    except Exception,e:
        print 'main loop',str(e)
  • Maybe this would help https://stackoverflow.com/questions/32400867/pandas-read-csv-from-url – Greg Sep 17 '17 at 10:28

1 Answers1

0

You should updates the pandas datareader with this fix https://github.com/pydata/pandas-datareader/issues/315

import pandas as pd
from pandas_datareader import data as web

start = datetime.datetime(2015, 7, 1)
end = datetime.datetime(2016, 7, 1)
data - web.DataReader('AAPL', 'yahoo',start, end)
lotteryman
  • 389
  • 1
  • 6
  • 21