atreadw1492 / yahoo_fin Goto Github PK
View Code? Open in Web Editor NEWScrape stock price history from new (Spring 2017) Yahoo Finance layout
License: MIT License
Scrape stock price history from new (Spring 2017) Yahoo Finance layout
License: MIT License
I have Python 3.8 installed on my system and see the following warning when using the tickers_sp500
function:
C:\Python38\lib\site-packages\yahoo_fin\stock_info.py:130: FutureWarning: The default value of regex will change from True to False in a future version. In addition, single character regular expressions will*not* be treated as literal strings when regex=True.
sp500["Symbol"] = sp500["Symbol"].str.replace(".", "-")
which can be traced back to the line of code below:
yahoo_fin/yahoo_fin/stock_info.py
Line 130 in 7302561
The issue can be reproduced by running the following code:
PS > python
>>> from yahoo_fin import stock_info as si
>>> t = si.tickers_sp500()
C:\Python38\lib\site-packages\yahoo_fin\stock_info.py:130: FutureWarning: The default value of regex will change from True to False in a future version. In addition, single character regular expressions will*not* be treated as literal strings when regex=True.
sp500["Symbol"] = sp500["Symbol"].str.replace(".", "-")
Specs of my system:
OS: Win10-64 bit
Python: 3.8.2
yahoo_fin: 0.8.8
I believe changing replace(".", "-")
to replace(".", "-", regex=True)
in the line of code referenced above should take care of the warning (but I haven't tested it yet). See this issue referenced from the Pandas docs.
At the current time (10pm EST) Calling stock_info.get_market_status () will return "POSTPOST'
Not sure if there is an error in the code.
Hi,
First of all, thanks for this wonderful library.
I try to obtain the call put info via get_options_chain
and the ticker I used was ^NDX.
However I found that the data dtype for Open interest, pct change and volume are all regarded as type object , i.e. string.
I have try to convert it to numeric by
call_df['Open Interest'] = pd.to_numeric(call_df['Open Interest'], errors='coerce')
put_df['Open Interest'] = pd.to_numeric(put_df['Open Interest'], errors='coerce')
and it seemed failed.
if it is possible that the library can first do the data type check and do necessary data type convert first?
Thanks.
Since yesterday I am getting an error getting market_status.
File "/Users/skhan/Library/Python/3.8/lib/python/site-packages/yahoo_fin/stock_info.py", line 965, in get_market_status
quote_data = get_quote_data("^dji")
File "/Users/skhan/Library/Python/3.8/lib/python/site-packages/yahoo_fin/stock_info.py", line 951, in get_quote_data
raise AssertionError("""Invalid response from server. Check if ticker is
AssertionError: Invalid response from server. Check if ticker is
valid.
ConnectionRefusedError: [Errno 61] Connection refused
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPSConnection object at 0x7fe84e2d5220>: Failed to establish a new connection: [Errno 61] Connection refused
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='query1.finance.yahoo.com', port=443): Max retries exceeded with url: /v8/finance/chart/PLUG?period1=7223400&period2=1616430229&interval=1d&events=div%2Csplits (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7fe84e2d5220>: Failed to establish a new connection: [Errno 61] Connection refused'))
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='query1.finance.yahoo.com', port=443): Max retries exceeded with url: /v8/finance/chart/PLUG?period1=7223400&period2=1616430229&interval=1d&events=div%2Csplits (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7fe84e2d5220>: Failed to establish a new connection: [Errno 61] Connection refused'))
Why do I keep getting thees four errors when trying to get live price for a stock?
Seems to be an issue with line 89 in stock_info in the get_data function. Result is "KeyError: 'adjclose'" which implies that adjclose is not a feature of that dataset. I tried removing the 'adjclose' element, but a new issue appeared: "KeyError: 'timestamp'" within the temp_time line.
get_balance_sheet() does not return "Invested Capital", even though it is present on Yahoo Finance.
For example, for AAPL:
>>> si.get_balance_sheet("AAPL")
endDate 2020-09-26 2019-09-28 2018-09-29 2017-09-30
Breakdown
totalLiab 258549000000 248028000000 258578000000 241272000000
totalStockholderEquity 65339000000 90488000000 107147000000 134047000000
otherCurrentLiab 47867000000 43242000000 39293000000 38099000000
totalAssets 323888000000 338516000000 365725000000 375319000000
commonStock 50779000000 45174000000 40201000000 35867000000
otherCurrentAssets 11264000000 12352000000 12087000000 13936000000
retainedEarnings 14966000000 45898000000 70400000000 98330000000
otherLiab 46108000000 50503000000 48914000000 43251000000
treasuryStock -406000000 -584000000 -3454000000 -150000000
otherAssets 33952000000 32978000000 22283000000 18177000000
cash 38016000000 48844000000 25913000000 20289000000
totalCurrentLiabilities 105392000000 105718000000 115929000000 100814000000
shortLongTermDebt 8773000000 10260000000 8784000000 6496000000
otherStockholderEquity -406000000 -584000000 -3454000000 -150000000
propertyPlantEquipment 45336000000 37378000000 41304000000 33783000000
totalCurrentAssets 143713000000 162819000000 131339000000 128645000000
longTermInvestments 100887000000 105341000000 170799000000 194714000000
netTangibleAssets 65339000000 90488000000 107147000000 134047000000
shortTermInvestments 52927000000 51713000000 40388000000 53892000000
netReceivables 37445000000 45804000000 48995000000 35673000000
longTermDebt 98667000000 91807000000 93735000000 97207000000
inventory 4061000000 4106000000 3956000000 4855000000
accountsPayable 42296000000 46236000000 55888000000 44242000000
But on Yahoo Finance:
Breakdown 9/30/2020 9/30/2019 9/30/2018 9/30/2017
Total Assets 323,888,000 338,516,000 365,725,000 375,319,000
Total Liabilities Net Minority Interest 258,549,000 248,028,000 258,578,000 241,272,000
Total Equity Gross Minority Interest 65,339,000 90,488,000 107,147,000 134,047,000
Total Capitalization 164,006,000 182,295,000 200,882,000 231,254,000
Common Stock Equity 65,339,000 90,488,000 107,147,000 134,047,000
Net Tangible Assets 65,339,000 90,488,000 107,147,000 126,032,000
Working Capital 38,321,000 57,101,000 14,473,000 27,831,000
Invested Capital 177,775,000 198,535,000 221,630,000 249,727,000
Tangible Book Value 65,339,000 90,488,000 107,147,000 126,032,000
Total Debt 112,436,000 108,047,000 114,483,000 115,680,000
Net Debt 74,420,000 59,203,000 88,570,000 95,391,000
Share Issued 16,976,763 17,772,944 19,019,944 20,504,804
Ordinary Shares Number 16,976,763 17,772,944 19,019,944 20,504,804
Is the volume off for anyone else when retrieving gainers or losers?
yahoo_gainers
Symbol Name Price (Intraday) ... Avg Vol (3 month) Market Cap PE Ratio (TTM)
0 AMKR Amkor Technology, Inc. 14.6700 ... 8.646730e+14 3.517000e+09 70.20
yahoo_gainers['Volume'][0]
3618000.0
yahoo_gainers['Avg Vol (3 month)'][0]
864673000000000.0
Here's the actual volume:
yahoo.get_quote_table('AMKR')
{'1y Target Est': 7.73, '52 Week Range': '5.74 - 14.81', 'Ask': '14.66 x 1400', 'Avg. Volume': 864673.0, 'Beta (3Y Monthly)': 1.66, 'Bid': '14.63 x 1100', "Day's Range": '13.15 - 14.81', 'EPS (TTM)': 0.21, 'Earnings Date': 'Oct 28, 2019', 'Ex-Dividend Date': nan, 'Forward Dividend & Yield': 'N/A (N/A)', 'Market Cap': '3.502B', 'Open': 13.46, 'PE Ratio (TTM)': 69.9, 'Previous Close': 11.08, 'Quote Price': 14.614999771118164, 'Volume': 3980124.0}
Hi All. First time posting so apologies if I do anything wrong! Love the package and I've been using it for a while.
I'm getting key error: 'timestamp' when I run get_data for non-US tickers. E.g. 'AUGM.L'. It does work fine for tickers that dont need the extension e.g. 'msft'. I didnt get this error with previous versions either. Any thoughts?
yahoo_fin 0.8.8
yahoo_fin\stock_info.py, line 100, in get_data
temp_time = data["chart"]["result"][0]["timestamp"]
options.get_options_chain('AVD', 'May 21, 2021') gives this error.
File "/Users/birdchan/my_git/docker-airflow/venv/lib/python3.7/site-packages/yahoo_fin/options.py", line 36, in get_options_chain
puts = tables[1].copy()
https://finance.yahoo.com/quote/AVD/options?p=AVD&date=1621555200
Perhaps just return an empty dataframe.
si.get_data("spy", interval = "1wk").close.tail(10)
2020-07-06 317.589996
2020-07-13 321.720001
2020-07-20 320.880005
2020-07-27 326.519989
2020-08-03 334.570007
2020-08-10 336.839996
2020-08-17 339.480011
2020-08-24 350.579987
2020-08-31 345.390015
2020-09-04 342.570007
si.get_data("spy", interval = "1d").close.tail(40)
2020-07-13 314.839996
2020-07-14 318.920013
2020-07-15 321.850006
2020-07-16 320.790009
2020-07-17 321.720001
2020-07-20 324.320007
2020-07-21 325.010010
2020-07-22 326.859985
2020-07-23 322.959991
2020-07-24 320.880005
2020-07-27 323.220001
2020-07-28 321.170013
2020-07-29 325.119995
2020-07-30 323.959991
2020-07-31 326.519989
2020-08-03 328.790009
2020-08-04 330.059998
2020-08-05 332.109985
2020-08-06 334.329987
2020-08-07 334.570007
2020-08-10 335.570007
2020-08-11 332.799988
2020-08-12 337.440002
2020-08-13 336.829987
2020-08-14 336.839996
2020-08-17 337.910004
2020-08-18 338.640015
2020-08-19 337.230011
2020-08-20 338.279999
2020-08-21 339.480011
2020-08-24 342.920013
2020-08-25 344.119995
2020-08-26 347.570007
2020-08-27 348.329987
2020-08-28 350.579987
2020-08-31 349.309998
2020-09-01 352.600006
2020-09-02 357.700012
2020-09-03 345.390015
2020-09-04 342.570007
in weekly close, 2020-08-31 345.390015, 345.390015 is 2020-09-03 which is thursday, not friday, can you please fix it?
VTSAX and VTIAX are returning NaN for stock_info.get_live_price and stock_info.get_data today (2020-09-05).
finance.yahoo.com has the latest data for these. I'm not sure if Yahoo has a bug that broke yahoo_fin or whether the bug is in yahoo_fin.
Thanks for this module. I was very happy to find it.
hi, for some tickers no dividends were available and the function raise 'AssertionError', is it possible to return 'False' instead of 'AssertionError'.
Thanks.
Hi
When i call get_earnings_history with interval='1mo', for the current month, i get two rows. i feel it should simply be the price up to the current date or maybe a parameter to indicate how to deal with that
2021-02-01 3731.169922 3950.429932 3725.620117 3811.149902 3811.149902 98596960000 ^GSPC
2021-03-01 3842.510010 3994.409912 3723.340088 3972.889893 3972.889893 120863560000 ^GSPC
2021-04-01 3992.780029 4218.779785 3992.780029 4181.169922 4181.169922 82869290000 ^GSPC
2021-05-01 4191.979980 4209.390137 4128.589844 4201.620117 4201.620117 17036160000 ^GSPC
2021-05-07 4210.339844 4236.720215 4201.640137 4228.870117 4228.870117 543666845 ^GSPC
This causes a problem if i want to see monthly performance to date for the last month. The following would yield an incorrect value for the current month - it should use current day's close along with previous months close.
`df['ret_pct'] = df['close'].pct_change(1) * 100`
Perhaps a function similar to:
get_market_status()
That would return wheter the market is open, closed, after hours, or premarket.
I will be short: Can you please add a function to get the sector information for a specified ticker?
Hi,
The historical data function return a pandas dataframe containing strange empty cells
I do the following
ticker = '^HSI'
yf_request = get_data(ticker)
and save dataframe as csv
In the csv, I found that some rows have only dates but all other cells are empty
for example, 21/10/2016 and 23/8/2017
I am not sure if this is an issue with code or simply quality of data source. I am pulling historical earnings for AAPL using the get_earnings_history function and noticed a couple of data issues:
I am guessing it may be an issue at the source - maybe needs some cleaning.
Has error on ticker "CL=F"
File "/usr/local/lib/python3.9/site-packages/yahoo_fin/stock_info.py", line 197, in get_quote_table
price_etc = [elt for elt in tables if elt.iloc[0][0] == "Previous Close"][0]
IndexError: list index out of range
Hello,
I've noticed that the library html_requests is required to use get_expiration_dates (at least).
That might be worth adding to your requirements.txt, don't you think?
Just updated to the current version for yahoo_fin. Here is the traceback of the error. Thanks
from yahoo_fin import stock_info as si
Traceback (most recent call last):
File "yahoo.py", line 11, in
data = si.get_data(sym)
\local-packages\Python38\site-packages\yahoo_fin\stock_info.py", line 78, in get_data
raise AssertionError(resp.json())
\local-packages\Python38\site-packages\requests\models.py", line 898, in json
return complexjson.loads(self.text, **kwargs)
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.2800.0_x64__qbz5n2kfra8p0\lib\json_init_.py", line 357, in loads
return _default_decoder.decode(s)
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.2800.0_x64__qbz5n2kfra8p0\lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.2800.0_x64__qbz5n2kfra8p0\lib\json\decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
Title says it all. Can we get TTM as an option to the yearly/quarterly ranges?
When using get_quote_data() to get information of a REIT I'm getting this error:
'IndexError: list index out of range'
When I manually request this information directly from the site("https://query1.finance.yahoo.com/v7/finance/quote?symbols=") I get:
'{"quoteResponse":{"result":[],"error":null}}'
What are your thoughts to work around this issue?
Thanks
I am looking for a way to get sector info as well as details about the company. Is there a way to get the profile page. e.g. https://finance.yahoo.com/quote/AAPL/profile?p=AAPL
import yahoo_fin.stock_info as si
list=si.tickers_dow()
print(list)
#this returns the error
get_stats('arry')
throws:
Traceback (most recent call last): File "test.py", line 20, in <module> print(si.get_stats('arry')) File "/home/saswat/.local/lib/python3.6/site-packages/yahoo_fin/stock_info.py", line 242, in get_stats table.columns = ["Attribute" , "Value"] File "/home/saswat/.local/lib/python3.6/site-packages/pandas/core/generic.py", line 5154, in __setattr__ return object.__setattr__(self, name, value) File "pandas/_libs/properties.pyx", line 66, in pandas._libs.properties.AxisProperty.__set__ File "/home/saswat/.local/lib/python3.6/site-packages/pandas/core/generic.py", line 564, in _set_axis self._mgr.set_axis(axis, labels) File "/home/saswat/.local/lib/python3.6/site-packages/pandas/core/internals/managers.py", line 227, in set_axis f"Length mismatch: Expected axis has {old_len} elements, new " ValueError: Length mismatch: Expected axis has 4 elements, new values have 2 elements
It happens for all stocks (e.g., sol.mc
, neoen.pa
) for which quarterly-report numbers are not available for all quarters.
I'm having a hard time comparing the data gathered via yahoo_fin. It doesn't seem to match what I can see on the finance.yahoo.com page. For example, get_cash_flow('CSCO') returns most recent annual data reports on '2020-07-25' but the https://finance.yahoo.com/quote/csco/cash-flow?p=csco page shows '2020-07-31'.
The data gathered appears to be the same (though the you have to multiple the webpage values by 1000). Why the different dates?
When looping through a large number of symbols to retrieve options data, the data returned is out of date after ~300 requests to options.get_options_chain(ticker)
The last trade date no longer shows recent activity and the prices don't match.
This may be yahoo blocking mining attempts.
Can someone tell me how to use this method?
It seems everything I try it wont return anything
Running the example in this repo gives the following error:
File "C:\Program Files\Python37\lib\site-packages\yahoo_fin\stock_info.py", line 82, in get_data
result = result.sort_values("date")
File "C:\Program Files\Python37\lib\site-packages\pandas\core\frame.py", line 4719, in sort_values
k = self._get_label_or_level_values(by, axis=axis)
File "C:\Program Files\Python37\lib\site-packages\pandas\core\generic.py", line 1702, in _get_label_or_level_values
self._check_label_or_level_ambiguity(key, axis=axis)
File "C:\Program Files\Python37\lib\site-packages\pandas\core\generic.py", line 1656, in _check_label_or_level_ambiguity
raise ValueError(msg)
ValueError: 'date' is both an index level and a column label, which is ambiguous.
Is there a method similar to get_live_price("aapl"),
but that would provide the after-hours price after 4pm,
and the premarket price in the morning before 9:30am?
That would be nice to have.
I've noticed that the stock prices are represented internally as numpy.float64. Representing currency as floating points has known issues and can lead to round off error accumulation over a series of operations. Any plans to address this issue in the future?
The Requirements section in http://theautomatic.net/yahoo_fin-documentation/ should not have ftplib
, io
, and json
since they are part of Python already. Removing them would help people who run pip install -r requirements.txt
.
If interval is set to 1m, then the end_dte calculation
2021-05-26 13:32:06,612.612 [MainThread] [connectionpool.py:452 - _make_request() ] https://query1.finance.yahoo.com:443 "GET /v8/finance/chart/PCT?period1=1621603926&period2=1622035926&interval=1m&events=div%2Csplits HTTP/1.1" 200 None
Converting period2 (1622035926) comes out to be
GMT: Wednesday, May 26, 2021 1:32:06 PM
Your time zone: Wednesday, May 26, 2021 9:32:06 AM GMT-04:00 DST
Relative: 4 hours ago
After updating to Py 3.7.10 and reinstalling yahoo_fin 0.8.9, I am getting the following error:
`>>> si.get_live_price(ticker)
Traceback (most recent call last):
File "", line 1, in
File "/Volumes/Backup/Users/......./anaconda3/lib/python3.7/site-packages/yahoo_fin/stock_info.py", line 575, in get_live_price
df = get_data(ticker, end_date = pd.Timestamp.today() + pd.DateOffset(10))
File "/Volumes/Backup/Users/......./anaconda3/lib/python3.7/site-packages/yahoo_fin/stock_info.py", line 88, in get_data
raise AssertionError(resp.json())
File "/Volumes/Backup/Users/......./anaconda3/lib/python3.7/site-packages/requests/models.py", line 900, in json
return complexjson.loads(self.text, **kwargs)
File "/Volumes/Backup/Users/......./anaconda3/lib/python3.7/json/init.py", line 348, in loads
return _default_decoder.decode(s)
File "/Volumes/Backup/Users/......./anaconda3/lib/python3.7/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/Volumes/Backup/Users/......./anaconda3/lib/python3.7/json/decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
`
All the modules seem to be satisfying the dependency requirements of yahoo_fin
Today code like
a = si.get_quote_table ( 'AAPL' )
stop worked. When debug, seems, what it suddenly need html5lib. OK, installed.
Then, when try to run this code, get:
Traceback (most recent call last):
File "C:/Users/Shake/PycharmProjects/RoboAd/Collector.py", line 1811, in
a = si.get_quote_table ( 'AAPL' )
File "C:\Users\Shake.conda\envs\RobAd\lib\site-packages\yahoo_fin\stock_info.py", line 293, in get_quote_table
tables = pd.read_html(site)
File "C:\Users\Shake.conda\envs\RobAd\lib\site-packages\pandas\io\html.py", line 1100, in read_html
displayed_only=displayed_only,
File "C:\Users\Shake.conda\envs\RobAd\lib\site-packages\pandas\io\html.py", line 915, in _parse
raise retained
File "C:\Users\Shake.conda\envs\RobAd\lib\site-packages\pandas\io\html.py", line 895, in _parse
tables = p.parse_tables()
File "C:\Users\Shake.conda\envs\RobAd\lib\site-packages\pandas\io\html.py", line 213, in parse_tables
tables = self._parse_tables(self._build_doc(), self.match, self.attrs)
File "C:\Users\Shake.conda\envs\RobAd\lib\site-packages\pandas\io\html.py", line 545, in _parse_tables
raise ValueError("No tables found")
ValueError: No tables found
File "C:\Users\Acer\Desktop\Ray\test\venv\lib\site-packages\yahoo_fin\stock_info.py", line 765, in get_earnings
result["quarterly_results"] = pd.DataFrame.from_dict(temp["earningsChart"]["quarterly"])
TypeError: 'NoneType' object is not subscriptable
Hi,
This is a rare scenario, but just happened today: the stock GRPEF has a change rate of "+249,900.00%" in daily gainers. This throws an ValueError
exception in stock_info(491)
when converting str
to float
because of the comma sign. Please change the line from:
df["% Change"] = df["% Change"].map(lambda x: float(x.strip("%+")))
to
df["% Change"] = df["% Change"].map(lambda x: float(x.strip("%+").replace(",", "")))
(Apologies for not forking etc., I am still new to GitHub).
Let me know if the above makes sense.
Best,
Gil
Unable to run any stock price retrieval from the website.
Hi,
is it possible to scrape gainers loosers and most active from yahoo market screenners, attachend links below kindly let me know thank you
https://in.finance.yahoo.com/gainers/
Retrieving data has issues if extracting data for a long period. Consider the following stocks:
CROMPTON.NS and HDFCBANK.NS.
api used: data = get_data(ticker=stock, start_date=start_date, end_date=end_date,
index_as_date= True, interval = frequency)
start_date = '01/01/2014'
end_date = '01/10/2020'
. Now if frequency variable in above is "1mo" or "1d" there are no issues in output. But, if "1wk" is given we start getting different beginning points of the week and hence, when this is combined back we get alternate rows with nan.
For example data for "HDFCBANK.NS" is present for following two weeks (2016-05-03, and 2016-05-10) whereas for "CROMPTON.NS", data is present for "2016-05-08" and "2016-05-15" and hence despite being present from next week this causes issues. Both should have same week numbers to combine them. This mostly happens when stocks are listed after the "start_date" for one of the 2 stocks under consideration.
Awaiting comments and solution.
I have been running into an error where the "get_expiration_dates()" will return only a couple dates or an entirely empty list. For example when working it will return this:
MOS
['June 25, 2021', 'July 2, 2021', 'July 9, 2021', 'July 16, 2021', 'July 23, 2021', 'July 30, 2021', 'September 17, 2021', 'December 17, 2021', 'January 21, 2022', 'January 20, 2023']
But will occasionally run something like this:
MOS
['January 21, 2022', 'January 20, 2023']
or
FMC
[]
Resulting in an error like below because there is no dates in the list.
Traceback (most recent call last):
File "c:\Users\User\Documents\options.py", line 300, in
bo.topFive(chosen_sector)
File "c:\Users\User\Documents\options.py", line 116, in topFive
call = self.closestCallStrike(sector[i], cur_stock_price, closing_dates[0])
IndexError: list index out of range
Possible typo your website:
Page: http://theautomatic.net/2019/04/17/how-to-get-options-data-with-python/
Heading: How to get options data for each expiration date
nflx_dates= options.get_expiration_dates("nflx")
info = {}
for date in nflx_dates:
info[date] = options.get_options_chain("nflx")
To my understanding should be the following, since options.get_options_chain("nflx")
has not idea which "date" you want
nflx_dates= options.get_expiration_dates("nflx")
info = {}
for date in nflx_dates:
info[date] =options.get_options_data("nflx", expiry=date)
I haven't used your library, perhaps I'm mistaken
Hi,
New to this but I am getting these error messages when using yahoo_fin. Searched online to see what the cure is and haven't found anything. I know this is somehow related to making multiple queries within a given period of time. If I wait for a day or two, the methods work again but this is not a solution. Would appreciate it if someone who has solved it helps me out:
SSLError: HTTPSConnectionPool(host='finance.yahoo.com', port=443): Max retries exceeded with url: /quote/QCOM/options?p=QCOM (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1091)')))
At approx 17:15 GMT I started getting this error when getting the market status.
It had been working constantly throughout the day.
I was on 0.8.8 when I started getting this error and upgraded to 0.8.9 but still getting the issue
Python 3.9.6 (default, Jul 3 2021, 16:40:50)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
from yahoo_fin import stock_info
stock_info.get_market_status()
Traceback (most recent call last):
File "", line 1, in
File "/usr/local/lib/python3.9/dist-packages/yahoo_fin/stock_info.py", line 965, in get_market_status
quote_data = get_quote_data("^dji")
File "/usr/local/lib/python3.9/dist-packages/yahoo_fin/stock_info.py", line 951, in get_quote_data
raise AssertionError("""Invalid response from server. Check if ticker is
AssertionError: Invalid response from server. Check if ticker is
valid.
Hi,
All of the sudden, the get_data
function became useless due to a bad response from yahoo finance API. I constructed the URL manually and was able to get the data from the browser, but python responses still keep returning 403 unless I add the headers:
headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36'}
result = requests.get(site, params=params, headers=headers)
I don't know if you are planning to release a new version soon, and whether yahoo will eventually block this user agent fix, but in case it is useful, would it be possible to get a handle on the request headers within your code?
Thanks!
Thanks.
def get_events(ticker, start_date = None, end_date = None, index_as_date = True):
'''Downloads historical event data into a pandas data frame
@param: ticker
@param: start_date = None
@param: end_date = None
@param: index_as_date = True
'''
site = build_url(ticker , start_date , end_date)
resp = requests.get(site)
html = resp.content
html = html.decode()
start = html.index("eventsData")
end = html.index("ThemeStore")
needed = html[start:end]
needed = needed.strip('"eventsData":')
needed = needed.strip("""}]},''""")
needed = needed + "}]"
temp = loads(needed)
result = json_normalize(temp)
# fix date field
result['date'] = result['date'].map(lambda x: pd.datetime.fromtimestamp(x).date())
result['ticker'] = ticker.upper()
result = result[['ticker', 'date', 'type', 'data']]
# Unused: 'amount', 'splitRatio', 'numerator', 'denominator'
result = result.reset_index(drop = True)
if index_as_date:
result.index = result.date.copy()
result = result.sort_values("date")
del result["date"]
return result
si.get_quote_table('MYL')
/usr/local/lib/python3.6/dist-packages/yahoo_fin/stock_info.py in get_quote_table(ticker, dict_result)
293 tables = pd.read_html(site)
294
295 data = tables[0].append(tables[1])
296
297 data.columns = ["attribute" , "value"]
IndexError: list index out of range
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.