gpt4 book ai didi

python - 网址错误 :

转载 作者:行者123 更新时间:2023-11-30 22:32:21 26 4
gpt4 key购买 nike

只是想让这段代码直接从金融Python中运行其非常基本的代码

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>

最佳答案

带有参数的 quotes_historical_yahoo_ochl 函数尝试从 http://icart.yahoo.com/table.csv?a=0&b=2&c=2012&d=11&e=5&f 获取值=2013&s=AAPL&y=0&g=d&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

关于python - 网址错误 : <urlopen error [Errno 11001] getaddrinfo failed>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45518528/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com