letylin / pyprogbook

金融大數據首部曲 書名: Python 程式設計入門 — 金融商管實務案例 讀者可以在此下載教學資源含程式碼
53 stars 28 forks source link

RC_7_3 無法執行 #19

Open slinwu opened 7 years ago

slinwu commented 7 years ago

RC_7_3: 上網抓資料並畫K線圖

執行到 quotes = quotes_historical_yahoo_ohlc('AAPL', start, end) 一直出現URLError: <urlopen error [Errno 11001] getaddrinfo failed>, 請問是什麼問題 ?

letylin commented 7 years ago

你好: 我這裡確認網路正常下,執行是沒有錯誤,如下圖。 另外,請在windows的command視窗, 輸入conda list檢視matplotlib是否已安裝。 若沒有請command 視窗輸入pip matplotlib install, 確認有此套件後再執行

image

slinwu commented 7 years ago

你好:

我確認有安裝此套件 matplotlib 2.0.2 np112py36_0

以下是執行的LOG:

In [20]: runfile('D:/python/finance_demo.py', wdir='D:/python') Traceback (most recent call last):

File "", line 1, in runfile('D:/python/finance_demo.py', wdir='D:/python')

File "C:\Users\Amanda\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 880, in runfile execfile(filename, namespace)

File "C:\Users\Amanda\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile exec(compile(f.read(), filename, 'exec'), namespace)

File "D:/python/finance_demo.py", line 9, in quotes = quotes_historical_yahoo_ohlc('AAPL', start, end)

File "C:\Users\Amanda\Anaconda3\lib\site-packages\matplotlib\finance.py", line 455, in quotes_historical_yahoo_ohlc ochl=False)

File "C:\Users\Amanda\Anaconda3\lib\site-packages\matplotlib\finance.py", line 503, in _quotes_historical_yahoo fh = fetch_historical_yahoo(ticker, date1, date2, cachename)

File "C:\Users\Amanda\Anaconda3\lib\site-packages\matplotlib\finance.py", line 362, in fetch_historical_yahoo with contextlib.closing(urlopen(url)) as urlfh:

File "C:\Users\Amanda\Anaconda3\lib\urllib\request.py", line 223, in urlopen return opener.open(url, data, timeout)

File "C:\Users\Amanda\Anaconda3\lib\urllib\request.py", line 526, in open response = self._open(req, data)

File "C:\Users\Amanda\Anaconda3\lib\urllib\request.py", line 544, in _open '_open', req)

File "C:\Users\Amanda\Anaconda3\lib\urllib\request.py", line 504, in _call_chain result = func(*args)

File "C:\Users\Amanda\Anaconda3\lib\urllib\request.py", line 1346, in http_open return self.do_open(http.client.HTTPConnection, req)

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

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

runfile('D:/python/finance_demo.py', wdir='D:/python') Traceback (most recent call last):

File "", line 1, in runfile('D:/python/finance_demo.py', wdir='D:/python')

File "C:\Users\Amanda\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 880, in runfile execfile(filename, namespace)

File "C:\Users\Amanda\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile exec(compile(f.read(), filename, 'exec'), namespace)

File "D:/python/finance_demo.py", line 9, in quotes = quotes_historical_yahoo_ohlc('AAPL', start, end)

File "C:\Users\Amanda\Anaconda3\lib\site-packages\matplotlib\finance.py", line 455, in quotes_historical_yahoo_ohlc ochl=False)

File "C:\Users\Amanda\Anaconda3\lib\site-packages\matplotlib\finance.py", line 503, in _quotes_historical_yahoo fh = fetch_historical_yahoo(ticker, date1, date2, cachename)

File "C:\Users\Amanda\Anaconda3\lib\site-packages\matplotlib\finance.py", line 362, in fetch_historical_yahoo with contextlib.closing(urlopen(url)) as urlfh:

File "C:\Users\Amanda\Anaconda3\lib\urllib\request.py", line 223, in urlopen return opener.open(url, data, timeout)

File "C:\Users\Amanda\Anaconda3\lib\urllib\request.py", line 526, in open response = self._open(req, data)

File "C:\Users\Amanda\Anaconda3\lib\urllib\request.py", line 544, in _open '_open', req)

File "C:\Users\Amanda\Anaconda3\lib\urllib\request.py", line 504, in _call_chain result = func(*args)

File "C:\Users\Amanda\Anaconda3\lib\urllib\request.py", line 1346, in http_open return self.do_open(http.client.HTTPConnection, req)

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

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


17/8/2 (週三),letylin notifications@github.com 寫道:

主旨: Re: [letylin/pyprogbook] RC_7_3 無法執行 (#19) 收件者: "letylin/pyprogbook" pyprogbook@noreply.github.com 副本: "slinwu" slinwu@yahoo.com.tw, "Author" author@noreply.github.com 日期: 2017年8月2日,三,下午12:53

我這裡確認網路正常下,執行是沒有錯誤,如下圖。

另外,請在windows的command視窗, 輸入conda list檢視matplotlib是否已安裝。 若沒有請command 視窗輸入pip matplotlib install, 確認有此套件後再執行

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

letylin commented 7 years ago

請問你的程式碼可以貼上來給我測看看, 我這裡沒有問題的。

letylin commented 7 years ago

可能是系統, 軟體環境問題, 能否同一支程式, 在另一台電腦測試過是否也出現同樣問題。程式碼本身應沒有錯。

slinwu commented 7 years ago

我直接用你網路上的執行

RC_7_3: 上網抓資料並畫K線圖

import matplotlib.pyplot as plt from matplotlib.dates import DateFormatter from matplotlib.finance import quotes_historical_yahoo_ohlc, candlestick_ohlc

下載資料起迄日, 日期格式與股票代號

start = (2016, 4, 1) end = (2016, 4, 25) weekFormatter = DateFormatter('%b %d') # 例如, Jan 03 2016 quotes = quotes_historical_yahoo_ohlc('AAPL', start, end)

若抓取的資料是空字串則離開系統

if len(quotes) == 0: raise SystemExit

設定繪圖區域的格式化

fig, ax = plt.subplots() ax.xaxis_date() plt.setp(plt.gca().get_xticklabels(), rotation=45, horizontalalignment='right')

畫K線圖並顯示

candlestick_ohlc(ax, quotes, width=0.6) plt.show()


17/8/2 (週三),letylin notifications@github.com 寫道:

主旨: Re: [letylin/pyprogbook] RC_7_3 無法執行 (#19) 收件者: "letylin/pyprogbook" pyprogbook@noreply.github.com 副本: "slinwu" slinwu@yahoo.com.tw, "Author" author@noreply.github.com 日期: 2017年8月2日,三,下午1:58

可能是系統, 軟體環境問題, 能否同一支程式, 在另一台電腦測試過是否也出現同樣問題。程式碼本身應沒有錯。

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

letylin commented 7 years ago

我這邊確定可以正常執行。你的anaconda是什麼版本?

letylin commented 7 years ago

你的作業系統與anaconda版本是?

slinwu commented 7 years ago

windows8 Python3.6.1 Anaconda 3.4.4.0

slinwu commented 7 years ago

windows8 Python3.6.1 Anaconda 3.4.4.0

17/8/2 (週三),letylin notifications@github.com 寫道:

主旨: Re: [letylin/pyprogbook] RC_7_3 無法執行 (#19) 收件者: "letylin/pyprogbook" pyprogbook@noreply.github.com 副本: "slinwu" slinwu@yahoo.com.tw, "Author" author@noreply.github.com 日期: 2017年8月2日,三,下午2:41

你的作業系統與anaconda版本是?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

letylin commented 7 years ago

只差在我是windows7, 我正在測google finance api, 預計下週會測完,下週再分享給你好嗎? 若忘了, 再提醒我。

slinwu commented 7 years ago

謝謝

17/8/2 (週三),letylin notifications@github.com 寫道:

主旨: Re: [letylin/pyprogbook] RC_7_3 無法執行 (#19) 收件者: "letylin/pyprogbook" pyprogbook@noreply.github.com 副本: "slinwu" slinwu@yahoo.com.tw, "Author" author@noreply.github.com 日期: 2017年8月2日,三,下午3:42

只差在我是windows7, 我正在測google finance api, 預計下週會測完,下週再分享給你好嗎? 若忘了, 再提醒我。

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

letylin commented 6 years ago

github的討論參與者您好! 您在這邊的留言我們比較難在第一時間收到資訊, 所以在這邊邀請您加入我們的LINE@ 1對1聊天群組, 您可以在LINE上討論有關於書中的問題, 讓我們能快速知道您的疑問並與您討論!

LINE@ID:@iex5378o ★☆★使用手機者點選以下網址或使用電腦者掃描以下QRCode立即加入群組★☆★ https://line.me/R/ti/p/%40iex5378o

line