JECSand / yahoofinancials

A powerful financial data module used for pulling data from Yahoo Finance. This module can pull fundamental and technical data for stocks, indexes, currencies, cryptos, ETFs, Mutual Funds, U.S. Treasuries, and commodity futures.
https://pypi.python.org/pypi/yahoofinancials
MIT License
896 stars 214 forks source link

not working - get_financial_data() #182

Open daniel-fcm opened 4 months ago

daniel-fcm commented 4 months ago

I have issue to get this information - it is not working at all anymore:

from yahoofinancials import YahooFinancials
yahoo_financials = YahooFinancials('AAPL')
print(yahoo_financials.get_financial_data())

Same problem with: get_stock_profile_data()

Is this a yahoo problem, or something in the package, which can be done. I run now a test before my script is running like:

def function_test(max_tests):

    info = YahooFinancials('AAPL')
    start_local = dt.datetime(2024, 1, 1).strftime('%Y-%m-%d')
    end_local = datetime.today().strftime('%Y-%m-%d')

    try:
        response = info.get_net_income()
        print(f'pos (1/{max_tests}): get_net_income ({response})')
    except:
        print('neg (1/{max_tests}): get_net_income')

    try:
        response = info.get_historical_price_data(start_date=start_local, 
                                                    end_date=end_local, 
                                                    time_interval='daily')
        print(f'pos (2/{max_tests}): get_historical_price_data ({response})')
    except:
        print('neg (2/{max_tests}): get_historical_price_data')

    try:
        response = info.get_financial_stmts('annual', ['balance'])
        print(f'pos (3/{max_tests}): get_financial_stmts BALANCE ({response})')
    except:
        print('neg (3/{max_tests}): get_financial_stmts BALANCE')

    try:
        response = info.get_financial_stmts('annual', ['income'])
        print(f'pos (4/{max_tests}): get_financial_stmts INCOME ({response})')
    except:
        print('neg (4/{max_tests}): get_financial_stmts INCOME')

    try:
        response = info.get_financial_stmts('annual', ['cash'])
        print(f'pos (5/{max_tests}): get_financial_stmts CASH ({response})')
    except:
        print('neg (5/{max_tests}): get_financial_stmts CASH')

    try:
        response = info.get_stock_profile_data()
        print(f'pos (6/{max_tests}): get_stock_profile_data ({response})')
    except:
        print('neg (6/{max_tests}): get_stock_profile_data')

    try:
        response = info.get_stock_quote_type_data()
        print(f'pos (7/{max_tests}): get_stock_quote_type_data ({response})')
    except:
        print('neg (7/{max_tests}): get_stock_quote_type_data')

    try:
        response = info.get_key_statistics_data()
        print(f'pos (8/{max_tests}): get_key_statistics_data ({response})')
    except:
        print('neg (8/{max_tests}): get_key_statistics_data')

    try:
        response = info.get_earnings_per_share()
        print(f'pos (9/{max_tests}): get_earnings_per_share ({response})')
    except:
        print('neg (9/{max_tests}): get_earnings_per_share')

    try:
        response = info.get_currency()
        print(f'pos (10/{max_tests}): get_currency ({response})')
    except:
        print('neg (10/{max_tests}): get_currency')

    try:
        response = info.get_beta()
        print(f'pos (11/{max_tests}): get_beta ({response})')
    except:
        print('neg (11/{max_tests}): get_beta')

    try:
        response = info.get_pe_ratio()
        print(f'pos (12/{max_tests}): get_pe_ratio ({response})')
    except:
        print('neg (12/{max_tests}): get_pe_ratio')

    try:
        response = info.get_market_cap()
        print(f'pos (13/{max_tests}): get_market_cap ({response})')
    except:
        print('neg (13/{max_tests})v: get_market_cap')

    try:
        response = info.get_financial_data()
        print(f'pos (14/{max_tests}): get_financial_data ({response})')
    except:
        print('neg (14/{max_tests}): get_financial_data')

max_tests = 14
function_test(max_tests)
print (f'### test completed with 'AAPL' and {max_tests} functions')
datatalking commented 4 months ago

@daniel-fcm I've rerun the first block of code and got the following output of the 'AAPL' stock so it seems to be working. What is the output of your code when you run it, can you provide a copy and paste of the stacktrace or screenshot?

Screen Shot 2024-02-27 at 2 49 32 AM Screen Shot 2024-02-27 at 2 51 32 AM
GRM65 commented 3 months ago

@datatalking,

I am having a similar issue.

Running the three lines listed at the beginning of your reply to @daniel-fcm in VSCode on a MacBookPro, I get no output at all, and nothing showing in the Call Stack panel. If I insert a generic print command between lines 3 and 4, that command will run and output the specified print string, and then the program just hangs. There are no error messages, and no other output.

Update: I apparently left the program running overnight and it eventually came up with a TypeError: TypeError: 'NoneType' object is not iterable

If I comment out line 4, the program runs and appears to terminate normally.

There seems to be some issue with the ".get_financial_data()" part. For that matter, the ".get_stock_profile_data()" method produces identical behavior: i.e. program hangs with no output.

I don't seem to have any problem using functions from the "yfinance" module, so the fetching of data from Yahoo is working in those instances.

Any ideas?

Any assistance or insight you can provide is greatly appreciated.

rtginfinity commented 3 months ago

seems to be an issue with latest version, I tried version 1.17 and it worked

GRM65 commented 3 months ago

seems to be an issue with latest version, I tried version 1.17 and it worked

Thank you! (Now why didn't I think of that? ...facepalm...)

For the benefit of others who might be having similar issues:

Version 1.17 still gave me a type error.

line 190, in _request_handler
    cur_url += "&crumb=" + self.crumb
               ~~~~~~~~~~^~~~~~~~~~~~
TypeError: can only concatenate str (not "NoneType") to str

I don't know whether this is related to leaving the dependencies from 1.20 in place, or if there is something else on my system that is different.

But version 1.18 seems to have worked.