【问题标题】:URLError: <urlopen error [Errno 11001] getaddrinfo failed>URLError: <urlopen 错误 [Errno 11001] getaddrinfo 失败>
【发布时间】:2021-07-06 17:36:09
【问题描述】:

只是试图让这段代码直接从 Python for Finance 中运行其非常基本的代码

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>

【问题讨论】:

  • 您能告诉我们您使用的是哪个 Python 版本吗?使用的库的安装版本是什么?您有稍长的错误消息吗?

标签: python matplotlib


【解决方案1】:

带有参数的quotes_historical_yahoo_ochl 函数尝试从http://ichart.yahoo.com/table.csv?a=0&amp;b=2&amp;c=2012&amp;d=11&amp;e=5&amp;f=2013&amp;s=AAPL&amp;y=0&amp;g=d&amp;ignore=.csv 获取当前或不再起作用的值...

更新

您可以尝试使用 Value 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

【讨论】:

  • 您能否提供一种方法来执行此操作
  • 嗨,显然雅虎在 5 月放弃了支持。你能用valueviz这样的替代方法吗?
  • 感谢您的帮助。如果您可以提出问题,我们将不胜感激。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-09-26
  • 2020-01-28
  • 1970-01-01
  • 2014-05-16
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多