2017-08-05 80 views
0

只是試圖讓這個代碼來運行其非常基本的直出了的Python的財務URLError:<的urlopen錯誤[錯誤11001]的getaddrinfo失敗>

import datetime 
import matplotlib.pyplot as plt 
from matplotlib.finance import quotes_historical_yahoo_ochl 
from matplotlib.dates import MonthLocator,DateFormatter 
ticker='AAPL' 
begdate = datetime.date(2012, 1, 2) 
enddate = datetime.date(2013, 12, 5) 
months = MonthLocator(range (1,13), bymonthday=1, interval = 3) 
monthsFmt = DateFormatter("%b '%y") 
x = quotes_historical_yahoo_ochl(ticker,begdate,enddate) 
if len(x) == 0: 
    print ("found no quotes") 
    raise SystemExit 
dates =[q[0] for q in x] 
closes = [q[4] for q in x] 
fig, ax = plt.subplots() 
ax.plot_date(dates,closes, '-') 
ax.xaxis.set_major_locator(months) 
ax.xaxis.set_major_formatter(monthsFmt) 
ax.xaxis.set_minor_locator(mondays) 
ax.autoscale_view() 
ax.grid(True) 
fig.autofmt_xdate() 

當它運行我得到這個錯誤:

File "C:\ProgramData\Anaconda3\lib\urllib\request.py", line 1320, in do_open 
    raise URLError(err) 

    URLError: <urlopen error [Errno 11001] getaddrinfo failed> 
+0

你能告訴我們你所使用的Python版本?所用庫的安裝版本是什麼?你有一個稍長的錯誤信息? – none

回答

1

quotes_historical_yahoo_ochl功能與參數試圖從http://ichart.yahoo.com/table.csv?a=0&b=2&c=2012&d=11&e=5&f=2013&s=AAPL&y=0&g=d&ignore=.csv不會在目前或繼續工作時得到的值...

更新

你可以用超值的Viz嘗試作爲一個實驗:

import requests 
params = {'tickers': 'MSFT', 'date': '2017-06-09'} 

r = requests.get('https://quantprice.herokuapp.com/api/v1.1/scoop/day', params=params) 

print r.text 

HTH

+0

你能提供一種方法來執行這個 –

+0

嗨,顯然雅虎在5月份放棄了支持。你可以使用一些替代像[valueviz](https://github.com/robomotic/valueviz)? – Alberto

相關問題