Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why can't the newly downloaded data run? It reports an error when I change the time for downloading the data. #1

Open
lmj282371 opened this issue Dec 8, 2024 · 5 comments

Comments

@lmj282371
Copy link

开始下载和处理股票数据...
处理 AAPL 中...
Failed to get ticker 'AAPL' reason: HTTPSConnectionPool(host='query1.finance.yahoo.com', port=443): Max retries exceeded with url: /v1/test/getcrumb (Caused by ProxyError('Unable to connect to proxy', FileNotFoundError(2, 'No such file or directory')))
处理 AAPL 时出错: 'Index' object has no attribute 'year'
And this issue occurs for all stocks.Adjusting the end time, whether forwards or backwards, and even restoring it to the original time, results in the same issue. Why is this happening?

@MilleXi
Copy link
Owner

MilleXi commented Dec 11, 2024

Noticed in your error message that it encounters a "ProxyError", it's mostly caused by your proxy setting. Double check your proxy settings and make sure u have ur proxy settings correctly in your code and you are able to access yahoo finance.

If you dont need the proxy or you have direct access to yfinance, you can simply remove the proxy parameter in the yf.download function in file "process_stock_data.py" line 91, the codes are given below.

data = yf.download(ticker, start=start_date, end=end_date, proxy="http://127.0.0.1:7890")
# change this to
data = yf.download(ticker, start=start_date, end=end_date)

@lmj282371
Copy link
Author

Thank you for your clarification, but I am still encountering issues with data download.
I have turned on my VPN, but it still cannot download data. I am receiving an error message:
处理 GE 中...
[100%%*] 1 of 1 completed

1 Failed download:
['MMM']: Exception('%ticker%: No timezone found, symbol may be delisted')
Failed to get ticker 'GE' reason: HTTPSConnectionPool(host='query1.finance.yahoo.com', port=443): Max retries exceeded with url: /v1/test/getcrumb (Caused by ProxyError('Unable to connect to proxy', FileNotFoundError(2, 'No such file or directory')))
[100%%*] 1 of 1 completed

1 Failed download:
['GE']: Exception('%ticker%: No timezone found, symbol may be delisted')
Failed to get ticker 'HON' reason: HTTPSConnectionPool(host='query1.finance.yahoo.com', port=443): Max retries exceeded with url: /v1/test/getcrumb (Caused by ProxyError('Unable to connect to proxy', FileNotFoundError(2, 'No such file or directory')))
处理 GE 时出错: 'Index' object has no attribute 'year'

@MilleXi
Copy link
Owner

MilleXi commented Dec 13, 2024

What operating system are you using? I have tried to call the yfinance API to download on a Linux system, but it failed. The same code is successful on Windows. If you are operating in Linux or WSL, I suggest you switch to Windows. In addition, you may need to check whether your proxy settings are correct, especially whether you have set the relevant proxy environment variables in the terminal.

I have to admit that it is really difficult to use yfinance in China. I also encountered many errors at that time. I suggest you look for similar situations in the issues of the yfinance official repository. .

@lmj282371
Copy link
Author

data = yf.download(ticker, start=start_date, end=end_date, proxy="http://127.0.0.1:7890")
我使用的是Windows系统上的PyCharm,python=3.9,yfinance是最新版本的
我打开VPN的报错:

处理 AAPL 中...
[100%**] 1 of 1 completed

1 Failed download:
['AAPL']: ProxyError(MaxRetryError("HTTPSConnectionPool(host='query1.finance.yahoo.com', port=443): Max retries exceeded with url: /v1/test/getcrumb (Caused by ProxyError('Unable to connect to proxy', FileNotFoundError(2, 'No such file or directory')))"))
Failed to get ticker 'SPY' reason: HTTPSConnectionPool(host='query1.finance.yahoo.com', port=443): Max retries exceeded with url: /v1/test/getcrumb (Caused by ProxyError('Unable to connect to proxy', FileNotFoundError(2, 'No such file or directory')))
[100%**] 1 of 1 completed

1 Failed download:
['SPY']: YFTzMissingError('$%ticker%: possibly delisted; no timezone found')
处理 AAPL 时出错: attempt to get argmax of an empty sequence

我关了VPN的报错是:

开始下载和处理股票数据...
处理 AAPL 中...
[100%] 1 of 1 completed
Failed to get ticker 'SPY' reason: Expecting value: line 1 column 1 (char 0)
[100%
] 1 of 1 completed

1 Failed download:
['SPY']: YFTzMissingError('$%ticker%: possibly delisted; no timezone found')
处理 AAPL 时出错: Unable to coerce to DataFrame, shape must be (753, 1): given (0, 1)

但我写了一个只单纯下载数据的代码

import yfinance as yf

定义股票代码、开始日期和结束日期

ticker = "MSFT" # 股票代码,例如苹果公司的股票代码是"AAPL"
start_date = "2020-01-01" # 开始日期,格式为"YYYY-MM-DD"
end_date = "2023-12-31" # 结束日期,格式为"YYYY-MM-DD"

下载股票数据

stock_data = yf.download(ticker, start=start_date, end=end_date, proxy="http://127.0.0.1:7890")

显示数据

print(stock_data)

关了VPN是正常运行并能显示出数据
[100%**] 1 of 1 completed
Price Adj Close Close ... Open Volume
Ticker MSFT MSFT ... MSFT MSFT
Date ...
2020-01-02 153.630692 160.619995 ... 158.779999 22622100
2020-01-03 151.717743 158.619995 ... 158.320007 21116200
2020-01-06 152.109879 159.029999 ... 157.080002 20813700
2020-01-07 150.722977 157.580002 ... 159.320007 21634100
2020-01-08 153.123718 160.089996 ... 158.929993 27746500
... ... ... ... ... ...
2023-12-22 371.799683 374.579987 ... 373.679993 17091100
2023-12-26 371.879150 374.660004 ... 375.000000 12673100
2023-12-27 371.293518 374.070007 ... 373.690002 14905400
2023-12-28 372.494537 375.279999 ... 375.369995 14327000
2023-12-29 373.248932 376.040009 ... 376.000000 18723000

[1006 rows x 6 columns]

但打开VPN的报错是:
[100%**] 1 of 1 completed

1 Failed download:
['MSFT']: ProxyError(MaxRetryError("HTTPSConnectionPool(host='query1.finance.yahoo.com', port=443): Max retries exceeded with url: /v1/test/getcrumb (Caused by ProxyError('Unable to connect to proxy', FileNotFoundError(2, 'No such file or directory')))"))
Empty DataFrame
Columns: [(Adj Close, MSFT), (Close, MSFT), (High, MSFT), (Low, MSFT), (Open, MSFT), (Volume, MSFT)]
Index: []

我尝试了很多方法,还是不知道问题在哪,您能抽空帮我解决一下吗,万分感激

@MilleXi
Copy link
Owner

MilleXi commented Dec 16, 2024

好奇怪的问题,我用的是 windows+python3.12+vscode

我尝试了以下几种方式

  1. 打开代理,保留代码中的proxy参数 -- 能够正确下载,如下图
    屏幕截图 2024-12-16 140244

  2. 打开代理,移除代码中的proxy参数 -- 能够正确下载

  3. 关闭代理,移除代码中的proxy参数 -- 不能正确下载,如下图
    屏幕截图 2024-12-16 140713

  4. 关闭代理,保留代码中的proxy参数 -- 出现报错如下
    1 Failed download:
    ['HON']: ProxyError(MaxRetryError("HTTPSConnectionPool(host='query2.finance.yahoo.com', port=443): Max retries exceeded with url:

该报错与您所遇到的报错类似,因此我估计您的代理设置依旧有些问题,您是否有检查过

proxy="http://127.0.0.1:7890"

这里的参数设置是否正确,其中的7890是否与您设备上的端口一致

我尝试了一下,当我使用与我设备不一致的端口设置时,我遇到的报错如下,和您遇到的非常接近:
image

以上供您参考

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants