HTTP error while getting info of a ticker
stock = yf.Ticker("MSFT")
stock_name = stock.info["shortName"]
When I execute this code multiple times (this happens about 100 times a day) I got such an error:
HTTP Error 503: Service Unavailable Traceback (most recent call last): File "bot.py", line 327, in watchlist_notify stock_name = stock.info["shortName"] File "/Users/Sepy/dev/stockBot/venv/pythonBot/src/yfinance/yfinance/ticker.py", line 138, in info return self.get_info() File "/Users/Sepy/dev/stockBot/venv/pythonBot/src/yfinance/yfinance/base.py", line 416, in get_info self._get_fundamentals(proxy) File "/Users/Sepy/dev/stockBot/venv/pythonBot/src/yfinance/yfinance/base.py", line 284, in _get_fundamentals holders = _pd.read_html(url) File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pandas/util/_decorators.py", line 296, in wrapper return func(*args, **kwargs) File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pandas/io/html.py", line 1086, in read_html return _parse( File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pandas/io/html.py", line 898, in _parse tables = p.parse_tables() File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pandas/io/html.py", line 217, in parse_tables tables = self._parse_tables(self._build_doc(), self.match, self.attrs) File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pandas/io/html.py", line 736, in _build_doc raise e File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pandas/io/html.py", line 717, in _build_doc with urlopen(self.io) as f: File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pandas/io/common.py", line 137, in urlopen return urllib.request.urlopen(*args, **kwargs) File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 222, in urlopen return opener.open(url, data, timeout) File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 531, in open response = meth(req, response) File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 640, in http_response response = self.parent.error( File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 569, in error return self._call_chain(*args) File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 502, in _call_chain result = func(*args) File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 649, in http_error_default raise HTTPError(req.full_url, code, msg, hdrs, fp) urllib.error.HTTPError: HTTP Error 503: Service Unavailable
What could be the reasons for the problem?
As per mozilla webpage https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/503, the server is down for maintenance, or is overloaded. As you suggest you are requesting you many time per day, you may be temporarily banned from yahoo.
It should be interesting to look to the response's header. You may have a retry-after header that would give more clue about this issue.
Anyway, this error is on yahoo server side, perhaps on your application if you request too much, but I believe not on yfinance.
@sepy97 @OlivierLuG Were you able to solve this error? I keep having the same issue and now have tried extending my time in between queries to 8 seconds and I still get this error. I'm going to try extending the time to 30 seconds.
Is there any place to go into the YFinance source code to change the user agent?
Try to see if the below solve your problem. I had the same issue and it was down to Yahoo blocking me as a scrapper.
https://github.com/ranaroussi/yfinance/issues/445 https://github.com/ranaroussi/yfinance/commit/6a8c637af758ff3de53f2ca3dafb6bf10f1902b9
@beglitis I tried that and I get this error Traceback (most recent call last): File "C:/Users/georg/OneDrive/Desktop/Desktop/All My Files/Coding Projects/Code/Neptune-Financial/Sectors/SectorSeperation-YFinance.py", line 36, in <module> dic = lis.info File "C:\Users\georg\anaconda3\lib\site-packages\yfinance\ticker.py", line 138, in info return self.get_info() File "C:\Users\georg\anaconda3\lib\site-packages\yfinance\base.py", line 459, in get_info self._get_fundamentals(proxy) File "C:\Users\georg\anaconda3\lib\site-packages\yfinance\base.py", line 339, in _get_fundamentals s[s.index == 'ratingYear']['Value'].values[0], IndexError: index 0 is out of bounds for axis 0 with size 0
A 503 Service Unavailable Error is an HTTP response status code indicating that your web server operates properly, but it can't temporarily handle the request at the moment. This error happen for a wide variety of reasons. Normally, this error can be due to a temporary overloading or maintenance being performed on the server and it is resolved after a period of time or once another thread has been released by web-server application. A 503 service unavailable is a temporary condition and the caller should retry after a reasonable period of time. Also check the http response headers for the description of the 503 error.
Does this still happen?