Closed dmoklaf closed 6 months ago
Where are you from? Which country?
France. I could try through proxies if it can help.
Hello,
I have the same error message, when try to use ticker.info functionality. Even after the last update from 6 Dec (0.2.33) the issue still exisit. I am from Bulgaria and do not use VPN, could you give some info does it possible to fix the issues locally using VPN or other option.
@NinoNinov try, please:
pip uninstall yfinance
pip install yfinance --upgrade --no-cache-dir
and remove yfinance.cache if it exists
and remove yfinance.cache if it exists
I prefer they keep cache and debug the error. What is the string?
2 feedbacks:
data.fetch_date
string is "2023-11-21T11:32:20.866294"
so it represents a valid date but, being a string, python refuses to "add" it to a datetime.datetime
. I am not familiar with yfinance internals but I assume there is a type issue with the data.fetch_date
fieldSounds easy to fix. #1084
and remove yfinance.cache if it exists
I prefer they keep cache and debug the error. What is the string?
The script is from public example. Is this bug general or only happen to me and dmoklaf?
import yfinance as yf
msft = yf.Ticker("MSFT")
# get all stock info
msft.info
# get historical market data
hist = msft.history(period="1mo")
and the issues is:
HTTPError Traceback (most recent call last)
Untitled-1.ipynb Cell 1 line 6
[3](vscode-notebook-cell:Untitled-1.ipynb?jupyter-notebook#W1sdW50aXRsZWQ%3D?line=2) msft = yf.Ticker("MSFT")
[5](vscode-notebook-cell:Untitled-1.ipynb?jupyter-notebook#W1sdW50aXRsZWQ%3D?line=4) # get all stock info
----> [6](vscode-notebook-cell:Untitled-1.ipynb?jupyter-notebook#W1sdW50aXRsZWQ%3D?line=5) msft.info
[8](vscode-notebook-cell:Untitled-1.ipynb?jupyter-notebook#W1sdW50aXRsZWQ%3D?line=7) # get historical market data
[9](vscode-notebook-cell:Untitled-1.ipynb?jupyter-notebook#W1sdW50aXRsZWQ%3D?line=8) hist = msft.history(period="1mo")
File [c:\Users\Nino\anaconda3\lib\site-packages\yfinance\ticker.py:138](file:///C:/Users/Nino/anaconda3/lib/site-packages/yfinance/ticker.py:138), in Ticker.info(self)
[136](file:///C:/Users/Nino/anaconda3/lib/site-packages/yfinance/ticker.py:136) @property
[137](file:///C:/Users/Nino/anaconda3/lib/site-packages/yfinance/ticker.py:137) def info(self) -> dict:
--> [138](file:///C:/Users/Nino/anaconda3/lib/site-packages/yfinance/ticker.py:138) return self.get_info()
File [c:\Users\Nino\anaconda3\lib\site-packages\yfinance\base.py:1501](file:///C:/Users/Nino/anaconda3/lib/site-packages/yfinance/base.py:1501), in TickerBase.get_info(self, proxy)
[1499](file:///C:/Users/Nino/anaconda3/lib/site-packages/yfinance/base.py:1499) def get_info(self, proxy=None) -> dict:
[1500](file:///C:/Users/Nino/anaconda3/lib/site-packages/yfinance/base.py:1500) self._quote.proxy = proxy
-> [1501](file:///C:/Users/Nino/anaconda3/lib/site-packages/yfinance/base.py:1501) data = self._quote.info
[1502](file:///C:/Users/Nino/anaconda3/lib/site-packages/yfinance/base.py:1502) return data
File [c:\Users\Nino\anaconda3\lib\site-packages\yfinance\scrapers\quote.py:562](file:///C:/Users/Nino/anaconda3/lib/site-packages/yfinance/scrapers/quote.py:562), in Quote.info(self)
[559](file:///C:/Users/Nino/anaconda3/lib/site-packages/yfinance/scrapers/quote.py:559) @property
[560](file:///C:/Users/Nino/anaconda3/lib/site-packages/yfinance/scrapers/quote.py:560) def info(self) -> dict:
[561](file:///C:/Users/Nino/anaconda3/lib/site-packages/yfinance/scrapers/quote.py:561) if self._info is None:
--> [562](file:///C:/Users/Nino/anaconda3/lib/site-packages/yfinance/scrapers/quote.py:562) self._fetch(self.proxy)
...
[1018](file:///C:/Users/Nino/anaconda3/lib/site-packages/requests/models.py:1018) )
[1020](file:///C:/Users/Nino/anaconda3/lib/site-packages/requests/models.py:1020) if http_error_msg:
-> [1021](file:///C:/Users/Nino/anaconda3/lib/site-packages/requests/models.py:1021) raise HTTPError(http_error_msg, response=self)
HTTPError: 404 Client Error: Not Found for url: https://query2.finance.yahoo.com/v6/finance/quoteSummary/MSFT?modules=financialData&modules=quoteType&modules=defaultKeyStatistics&modules=assetProfile&modules=summaryDetail&ssl=true
Output is truncated. View as a [scrollable element](command:cellOutput.enableScrolling?63b15f4e-4d30-460c-99b0-76e1dc7db8b2) or open in a [text editor](command:workbench.action.openLargeOutput?63b15f4e-4d30-460c-99b0-76e1dc7db8b2). Adjust cell output [settings](command:workbench.action.openSettings?%5B%22%40tag%3AnotebookOutputLayout%22%5D)...
@NinoNinov it's error from old code. Try latest version
@NinoNinov it's error from old code. Try latest version
I tried to updated to last version several time but still the same issue, as you can see from my screenshot made several minutes ago. https://i.ibb.co/F4sgLj2/yfinance.jpg
@NinoNinov The latest version is 0.2.33, but you have installed 0.2.24
@bot-unit many thanks for support! Now it is working, the issie was that I tried to update with comand:
pip install yfinance
which was working in the past but is not working now. Instead that used:
pip install yfinance --upgrade --no-cache-dir
amd now works.
@dmoklaf try to fix issue with second command
@NinoNinov I followed your reinstall procedure with the specific flags including --no-cache-dir
and the bug is still there. I may have time in the next two weeks to dig into these typing issues. The fix seems simple (may be a one liner), what worries me is the other parts of the library that I really don't use and don't know, including the cache whose existence is new to me. And why am I the only one to see this.
@dmoklaf the caching is needed for cookies. Since Yahoo started blocking requests without crumbs, we should obtain cookies, then crumb, and only then make requests.
@dmoklaf Give us the cookie cache database file, I want to understand how error happened. I've updated README to explain where file is.
Here are the cache files. Let me know if I should perform another test with clean (reset) cache files. Even if small, I had to zip them as GitHub doesn't accept .db files Archive.zip
MacOS 14.2 Python 3.11.6 yfinance 0.2.33
I understand the problem but no idea how it happened. 2023-11-21T11:32:20.866294
is in the database, using T
to separate date from time instead of a space - this should be impossible because peewee
handes everything. The T
causes parse back into datetime
to fail.
Branch hotfix/cookie-cache-date
has a workaround, try it.
Branch
hotfix/cookie-cache-date
has a workaround, try it.
It works ! Now that you have identified the culprit being the storage format in Sqlite, I can complete the missing pieces as I know this part well: 1- Sqlite has no true DATETIME storage. Even if the field type "seems" to exist, it's just for Sqlite an alias for a string storage. 2-The mapping from a Python datetime to the stored string is performed by the Python sqlite3 driver. I don't know if peewee relies on it or not but, based on the bug you elucidated, it seems it does replicate the same issue described below. 3-The sqlite3 driver offers (until Python 3.12, this will be removed in a future release) a default mapping that is the one you were expecting (with a space between the date and the time). 4-But I had in my dependencies tree a third-party library which enforces a strict ISO8601 mapping to make sure all stored dates can be parsed following the ISO norm in its own Sqlite database. The ISO norm uses a T between the date and the time
Note: the Python documentation is confusing because it states that its default mapping is ISO-compliant. But this is wrong. Using a space is not ISO compliant and is a tolerance stemming from RFC 3339, not supported by all tools. Strict ISO forbids the space, and requires a T.
The future for Python may favor strict ISO as the documentation announces default mappings will be removed, and offers as a compensation mapping examples strictly based on ISO (and not based on the RFC 3339 tolerance): https://docs.python.org/3/library/sqlite3.html#default-adapters-and-converters-deprecated https://docs.python.org/3/library/sqlite3.html#sqlite3-adapter-converter-recipes
So your workaround may be going in the right direction.
Given this is an edge case, I have lowered priority for merge into dev
branch.
Hello @dmoklaf for the code below I receive again issue "404 Client Error: Not Found for url:" I use the same code with S&P 500 Data and everithing works fine, if I change nasdaq100[i] with nasdaq100[1], 2, 3 code is working. Do you have idea from where is comong that issue, I guess something with the list is not ok.
stock_data = PyTickerSymbols()
nasdaq100 = stock_data.get_stocks_by_index('NASDAQ 100')
nasdaq100 = pd.DataFrame(nasdaq100)
nasdaq100=nasdaq100['symbol'].tolist()
nasdaq100_len=len(nasdaq100)
list_stocks=[]
for i in range(0,nasdaq100_len):
stock = yf.Ticker(nasdaq100[i])
stock_i=stock.info
stock_i=pd.DataFrame.from_dict(stock_i.items())
stock_i.columns =['Name', 'Value']
stock_i.rename(columns = {'Value':nasdaq100[i]}, inplace = True)
list_stocks.append(stock_i)
S&P Code which is working
#Extracting actual companies in S&P 500 Index + calculating lenght of companies in the index
table=pd.read_html('https://en.wikipedia.org/wiki/List_of_S%26P_500_companies')
sp500 = table[0]
sp500 = sp500["Symbol"].tolist()
sp500_len = len(sp500)
#Table from which will merge coulumns into main table - adding more info about S&P 500
aditional_info_sp500=table[0]
aditional_info_sp500=aditional_info_sp500[["Symbol","Founded","GICS Sector","GICS Sub-Industry","Date added"]]
#For loop whcih to store data for S&P 500 companies from yfinance to DataFrame in Pandas
#IT IS LOADING APPROXIMATELY 5 MINUTES
list_stocks=[]
for i in range(0,sp500_len):
stock = yf.Ticker(sp500[i])
stock_i=stock.info
stock_i=pd.DataFrame.from_dict(stock_i.items())
stock_i.columns =['Name', 'Value']
stock_i.rename(columns = {'Value':sp500[i]}, inplace = True)
list_stocks.append(stock_i)
@NinoNinov I could reproduce your error, and simplified the case to this:
import yfinance
yfinance.Ticker("ATVI").info
which raises a 404 error.
This error is coming from Yahoo and not from this library, as Yahoo declares ATVI (Activision) as a private company: https://finance.yahoo.com/company/activision-422a?h=eyJlIjoiYWN0aXZpc2lvbi00MjJhIiwibiI6IkFjdGl2aXNpb24ifQ==&.tsrc=fin-srch
So this is an unrelated error that is not in the scope of this project.
Many thanks, PyTickerSymbols is not up to date, will scrap NASDAQ data from web.
Fixed by #1796
Describe bug
This tutorial code crashes now:
Simple code that reproduces your problem
See above
Debug log
Bad data proof
No response
yfinance
version0.2.32 (pip installed directly from Github GIT repository)
Python version
3.11.6
Operating system
MacOS Sonoma 14.1.1