无法建立新连接:[Errno -2]名称或服务未知

时间:2017-07-21 10:36:07

标签: python connection port

我在python上运行这个脚本:

import requests
url = "http://finance.yahoo.com/quote/AAPL?p=AAPL"
response = requests.get(url)
print(response)

我收到以下错误:

Traceback (most recent call last):
  File "python", line 6, in <module>
requests.exceptions.ConnectionError: HTTPConnectionPool(host='finance.yahoo.com', port=80): Max retries exceeded with url: /quote/AAPL?p=AAPL (Caused by NewConnectionError('<requests.packages.urllib3.connection.HTTPConnection object at 0x7fcbf36d3a20>: Failed to establish a new connection: [Errno -2] Name or service not known',))

可能是什么原因?

感谢

1 个答案:

答案 0 :(得分:1)

您的代码对我有用,所以我不确定。但是,如果从yahoo finance获取数据,请尝试使用api,这将节省您解析数据的费用。

http://www.jarloo.com/yahoo_finance/

只是请求无法获取的雅虎网站还是一般性错误?