ranaroussi / yfinance

Download market data from Yahoo! Finance's API
https://aroussi.com/post/python-yahoo-finance
Apache License 2.0
13.24k stars 2.34k forks source link

Cookie #2082

Open vw98075 opened 3 days ago

vw98075 commented 3 days ago

Describe bug

To my understanding of the Python code, once a fetched cookie is over 24 hours, the cookie is marked as invalid in the code. It will refresh the cookie when it is older than 24 hours.

Here is a header I get from the fc.yahoo.com end point:

Date: Thu, 10 Oct 2024 18:23:25 GMT Connection: keep-alive Server: ATS Cache-Control: no-store Content-Type: text/html Content-Language: en Set-Cookie: ...; Expires=Sat, 11 Oct 2025 00:23:25 GMT; Max-Age=31557600; Domain=.yahoo.com; Path=/; SameSite=None; Secure; HttpOnly Content-Length: 4744

The above header contains an expiration date. I wonder why the expiration date isn't used to determine whether refreshing the cookie is needed. Do I miss something?

Simple code that reproduces your problem

Periodically refresh, 24 hours seems fair.

    if cookie_dict['age'] > datetime.timedelta(days=1):
        return False

Debug log

NA

Bad data proof

No response

yfinance version

0.2.44

Python version

No response

Operating system

No response

ValueRaider commented 3 days ago

I was lazy and rushing it, that's all. #1084

vw98075 commented 2 days ago

Thanks for the info. It is understandable when you have too many things to work on a project. I have little knowledge of Python. Otherwise, I would submit a pull request for a related change.

ValueRaider commented 1 day ago

If you use yfinance regularly, you probably have enough Python knowledge.