Skip to content

Commit 2047ddc

Browse files
committed
Add logic to setup a session when logging in is unsuccessful
1 parent 3a06edb commit 2047ddc

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

yahooquery/base.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -1000,14 +1000,23 @@ def login(self) -> None:
10001000
if _has_selenium:
10011001
instance = YahooFinanceHeadless(self.username, self.password)
10021002
instance.login()
1003-
self.session.cookies = instance.cookies
1003+
if instance.cookies:
1004+
self.session.cookies = instance.cookies
1005+
return
1006+
1007+
else:
1008+
logger.warning(
1009+
"Unable to login and/or retrieve the appropriate cookies. This is "
1010+
"most likely due to Yahoo Finance instituting recaptcha, which "
1011+
"this package does not support."
1012+
)
10041013

10051014
else:
10061015
logger.warning(
10071016
"You do not have the required libraries to use this feature. Install "
10081017
"with the following: `pip install yahooquery[premium]`"
10091018
)
1010-
self.session = setup_session(self.session, self._setup_url)
1019+
self.session = setup_session(self.session, self._setup_url)
10111020

10121021
def _chunk_symbols(self, key, params={}, chunk=None, **kwargs):
10131022
current_symbols = self.symbols

0 commit comments

Comments
 (0)