dpguthrie / yahooquery

Python wrapper for an unofficial Yahoo Finance API
https://yahooquery.dpguthrie.com
MIT License
777 stars 137 forks source link

User not logging in #183

Open MaxL777 opened 1 year ago

MaxL777 commented 1 year ago

Discussed in https://github.com/dpguthrie/yahooquery/discussions/181

Originally posted by **MaxL777** April 21, 2023 I am using yahooquery version is 2.3.1 and when running the below code I get an error. I installed yahooquery[premium]. I am certain my username and pw are correct. Any help is appreciated. **Here is the code:** `from yahooquery import Ticker symbols = ['fb', 'aapl', 'amzn', 'nflx', 'goog'] faang = Ticker(symbols, asynchronous=True) faang.login(username="my_user_name@yahoo.com", password="my_pw") income_statement = faang.p_income_statement('q') cash_flow = faang.p_cash_flow('q') balance_sheet = faang.p_balance_sheet('q') company_360 = faang.p_company_360 vma = faang.p_valuation_measures('a') vmq = faang.p_valuation_measures('q') vmm = faang.p_valuation_measures('m')` vma **Here is the error:** `{'amzn': 'User is not logged in', 'fb': 'User is not logged in', 'goog': 'User is not logged in', 'nflx': 'User is not logged in', 'aapl': 'User is not logged in'}`
ms82494 commented 1 year ago

Take a look at my reply to Issue #180. I don't use the exact same way to login as you do, but if your Ticker object's crumb is None then your issue might be the same as what I had. My problem got fixed by patching login.py.

srujantaticherla commented 9 months ago

Did anyone get around the issue without patching the login.py ..?

ms82494 commented 9 months ago

This was about an old version. If you use the current version of yahooquery you don't need any patch.

srujantaticherla commented 9 months ago

1) Re-installed the version of premium just to be sure.

(venv) 88665a400348:pythonProject1 tasrujan$ pip install yahooquery[premium] Requirement already satisfied: yahooquery[premium] in ./venv/lib/python3.11/site-packages (2.3.7)

2) Used the below code and running it in pycharm locally

from yahooquery import Ticker

symbols = ['fb', 'aapl', 'amzn', 'nflx', 'goog']

faang = Ticker(symbols, username="xxxxx@yahoo.com", password="xxxx")

income_statement = faang.p_income_statement('q') cash_flow = faang.p_cash_flow('q') balance_sheet = faang.p_balance_sheet('q')

company_360 = faang.p_company_360

vma = faang.p_valuation_measures('a') vmq = faang.p_valuation_measures('q') vmm = faang.p_valuation_measures('m')

print(vma)

The output is as below

{'fb': 'User is not logged in', 'aapl': 'User is not logged in', 'amzn': 'User is not logged in', 'nflx': 'User is not logged in', 'goog': 'User is not logged in'}

Process finished with exit code 0

Do I need to change anything to get the results..? Thanks a lot.

ms82494 commented 9 months ago

Apologies for the delay, I missed the notification of your message. I am not sure what problem you encounter. It just works for me:

Python 3.11.6 | packaged by conda-forge | (main, Oct  3 2023, 10:37:07) [Clang 15.0.7 ]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.18.1 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import yahooquery as yq

In [2]: import os, operator

In [3]: YUSER, YPASS = operator.itemgetter('YUSER','YPASS')(os.environ)

In [4]: yq.__version__
Out[4]: '2.3.7'

In [5]: yqclient = yq.Ticker('AAPL', username=YUSER, password=YPASS)

In [6]: yqclient.p_get_financial_data(types=['OrdinarySharesNumber', 'TangibleBo
   ...: okValue'], frequency='q', trailing=False)
Out[6]: 
         asOfDate periodType  ... OrdinarySharesNumber  TangibleBookValue
symbol                        ...                                        
AAPL   1985-09-30         3M  ...         1.385440e+10       5.505000e+08
AAPL   1986-09-30         3M  ...         1.402867e+10       6.941000e+08
AAPL   1987-09-30         3M  ...         1.412186e+10       8.365000e+08
AAPL   1988-09-30         3M  ...         1.375002e+10       1.003400e+09
AAPL   1989-09-30         3M  ...         1.414224e+10       1.485700e+09
...           ...        ...  ...                  ...                ...
AAPL   2022-09-30         3M  ...         1.594342e+10       5.067200e+10
AAPL   2022-12-31         3M  ...         1.584241e+10       5.672700e+10
AAPL   2023-03-31         3M  ...         1.572341e+10       6.215800e+10
AAPL   2023-06-30         3M  ...         1.564787e+10       6.027400e+10
AAPL   2023-09-30         3M  ...         1.555006e+10       6.214600e+10

[141 rows x 5 columns]

In [7]: 

I tried your code as well, and it works just fine for me (with my username/pwd combo, of course).

Some non-US users have reported problems with getting a valid cookie/crumb because the login flow is different for users accessing Yahoo from EU countries (for example). If you have access to a VPN with tunnels to the US, I'd suggest trying that. Good luck!

srujantaticherla commented 9 months ago

I was on my corporate vpn (actual physical location in US only) when testing the code. Logged off the vpn and could execute the code. Thank you.