ranaroussi / yfinance

Download market data from Yahoo! Finance's API
https://aroussi.com/post/python-yahoo-finance
Apache License 2.0
12.42k stars 2.25k forks source link

get_news() returns news not related to the given ticker #1956

Open AlexPlatin opened 1 month ago

AlexPlatin commented 1 month ago

Describe bug

I used yfinance to get news from different companies listed on various stock exchanges using method news (.get_news()) and it worked very well.

However, starting from March 2024 the get_news() method returns news not related to given ticker. I believe it now returns news from the main page of Yahoo Finance (see Bad data proof. For example, I asked about "1A9.F" ticker and it returned 'relatedTickers': ['CMOPF'] news)

Simple code that reproduces your problem

import yfinance as yf
msft = yf.Ticker("1A9.F")
msft.news

Debug log

DEBUG    Entering get()
DEBUG     url=https://query2.finance.yahoo.com/v1/finance/search?q=1A9.F
DEBUG     params=None
DEBUG     Entering _get_cookie_and_crumb()
DEBUG      cookie_mode = 'basic'
DEBUG      Entering _get_cookie_and_crumb_basic()
DEBUG       loaded persistent cookie
DEBUG       reusing cookie
DEBUG       crumb = 'f/nSB8VksED'
DEBUG      Exiting _get_cookie_and_crumb_basic()
DEBUG     Exiting _get_cookie_and_crumb()
DEBUG     response code=200
DEBUG    Exiting get()

Bad data proof

{'count': 13,
 'explains': [],
 'lists': [{'brandSlug': 'yahoo-finance',
            'dailyPercentGain': 0.8398355065208919,
            'followerCount': 61456,
            'iconUrl': 'https://edgecast-img.yahoo.net/mysterio/api/110f1012357c7b3e87d14912e7023f819b61278e7f0e90a3825821d2ef3c427c/finance/resizefill_w96_h96/https://s.yimg.com/uc/fin/img/most-bought-activist.png',
            'index': 'most-bought-by-activist-hedge-funds',
            'name': 'Most Bought By Activist Hedge Funds',
            'pfId': 'most_bought_by_activist_hedge_funds',
            'score': 15.645953,
            'slug': 'most-bought-by-activist-hedge-funds',
            'symbolCount': 18,
            'type': 'ALGO_WATCHLIST',
            'userId': '5SSSFLJVWAMDKUGZM5HLSSBNAY'},
           {'brandSlug': 'yahoo-finance',
            'dailyPercentGain': 0.5050837217231051,
            'followerCount': 41686,
            'iconUrl': 'https://edgecast-img.yahoo.net/mysterio/api/f1b1a50dcfdddcf42a67d2da1bb1c341e6f65992b3d89154b9020ae8a9ffa004/finance/resizefill_w96_h96/https://s.yimg.com/uc/fin/img/mostboughtHedgeFunds.png',
            'index': 'most-bought-by-hedge-funds',
            'name': 'Most Bought By Hedge Funds',
            'pfId': 'most_bought_by_hedge_funds',
            'score': 10.904234,
            'slug': 'most-bought-by-hedge-funds',
            'symbolCount': 30,
            'type': 'ALGO_WATCHLIST',
            'userId': '5SSSFLJVWAMDKUGZM5HLSSBNAY'},
           {'brandSlug': 'yahoo-finance',
            'dailyPercentGain': 1.119014997698063,
            'followerCount': 29897,
            'iconUrl': 'https://edgecast-img.yahoo.net/mysterio/api/9f2d41c327a5d20c8062b14f526038441141d5644b2b3a0efee2e12d9be1efe0/finance/resizefill_w96_h96/https://s.yimg.com/uc/finance/social/portfolio/most-watched.png',
            'index': 'most-watched',
            'name': 'Most Watched by Yahoo Finance Users',
            'pfId': 'most_watched',
            'score': 7.611414,
            'slug': 'most-watched',
            'symbolCount': 30,
            'type': 'ALGO_WATCHLIST',
            'userId': '5SSSFLJVWAMDKUGZM5HLSSBNAY'},
           {'brandSlug': 'trea',
            'dailyPercentGain': -0.2682118695951419,
            'followerCount': 23819,
            'iconUrl': 'https://edgecast-img.yahoo.net/mysterio/api/3c7c7b592c7aba2beee72abb1e520b85d6241aee639ea2e8033b96962ad2e126/finance/resizefill_w96_h96/https://s.yimg.com/uc/fin/img/iStock-476433472.png',
            'index': 'the-fight-against-covid19',
            'name': 'The Fight Against COVID19',
            'pfId': 'the_fight_against_covid19',
            'score': 6.4065385,
            'slug': 'the-fight-against-covid19',
            'symbolCount': 13,
            'type': 'ALGO_WATCHLIST',
            'userId': 'X3NJ2A7VDSABUI4URBWME2PZNM'}],
 'nav': [],
 'news': [{'link': 'https://finance.yahoo.com/m/41621b45-a35e-3ee7-9bfc-83208f5ef88b/warren-buffett-vs.-carl.html',
           'providerPublishTime': 1717391040,
           'publisher': 'Motley Fool',
           'relatedTickers': ['IEP'],
           'thumbnail': {'resolutions': [{'height': 933,
                                          'tag': 'original',
                                          'url': 'https://s.yimg.com/uu/api/res/1.2/7BnUe4BeZ..bO6lLQiG3bg--~B/aD05MzM7dz0xNDAwO2FwcGlkPXl0YWNoeW9u/https://media.zenfs.com/en/motleyfool.com/9b1a29f472887a127d65d8a72b330520',
                                          'width': 1400},
                                         {'height': 140,
                                          'tag': '140x140',
                                          'url': 'https://s.yimg.com/uu/api/res/1.2/qV4yrQGnvrOhp7Fa395lrw--~B/Zmk9ZmlsbDtoPTE0MDtweW9mZj0wO3c9MTQwO2FwcGlkPXl0YWNoeW9u/https://media.zenfs.com/en/motleyfool.com/9b1a29f472887a127d65d8a72b330520',
                                          'width': 140}]},
           'title': 'Warren Buffett vs. Carl Icahn: Is Berkshire Hathaway or '
                    'Icahn Enterprises a Better Stock for You?',
           'type': 'STORY',
           'uuid': '41621b45-a35e-3ee7-9bfc-83208f5ef88b'},
          {'link': 'https://finance.yahoo.com/news/analysis-trial-investors-weigh-trump-050333950.html',
           'providerPublishTime': 1717391013,
           'publisher': 'Reuters',
           'thumbnail': {'resolutions': [{'height': 533,
                                          'tag': 'original',
                                          'url': 'https://s.yimg.com/uu/api/res/1.2/fxWMIZxYI0EUrxpXdLnJXw--~B/aD01MzM7dz04MDA7YXBwaWQ9eXRhY2h5b24-/https://media.zenfs.com/en/reuters-finance.com/9c25d93290d6c1bce07a03726d8cfebf',
                                          'width': 800},
                                         {'height': 140,
                                          'tag': '140x140',
                                          'url': 'https://s.yimg.com/uu/api/res/1.2/TKLIoWj6NLK673W.kZxJzQ--~B/Zmk9ZmlsbDtoPTE0MDtweW9mZj0wO3c9MTQwO2FwcGlkPXl0YWNoeW9u/https://media.zenfs.com/en/reuters-finance.com/9c25d93290d6c1bce07a03726d8cfebf',
                                          'width': 140}]},
           'title': 'Analysis-After trial, investors weigh Trump 2.0 factor as '
                    'election looms',
           'type': 'STORY',
           'uuid': 'acf48aba-d381-3c12-95c6-4fbc0c335aa3'},
          {'link': 'https://finance.yahoo.com/m/87a0f0e5-7ebd-390d-a58d-2e22605357cc/dow-jones-futures-rise%3B.html',
           'providerPublishTime': 1717390973,
           'publisher': "Investor's Business Daily",
           'relatedTickers': ['NVDA', '^GSPC', '^DJI', 'COMP', 'QCOM'],
           'thumbnail': {'resolutions': [{'height': 563,
                                          'tag': 'original',
                                          'url': 'https://s.yimg.com/uu/api/res/1.2/vN4.NUyvgiN_4UzIAKqlBQ--~B/aD01NjM7dz0xMDAwO2FwcGlkPXl0YWNoeW9u/https://media.zenfs.com/en/ibd.com/a0e93b56357fe572742d0fcf66117149',
                                          'width': 1000},
                                         {'height': 140,
                                          'tag': '140x140',
                                          'url': 'https://s.yimg.com/uu/api/res/1.2/5zGENOL9gogmWSQfoXJyZg--~B/Zmk9ZmlsbDtoPTE0MDtweW9mZj0wO3c9MTQwO2FwcGlkPXl0YWNoeW9u/https://media.zenfs.com/en/ibd.com/a0e93b56357fe572742d0fcf66117149',
                                          'width': 140}]},
           'title': 'Dow Jones Futures Rise; Nvidia CEO Touts Next AI Chips, '
                    'And So Does AMD',
           'type': 'STORY',
           'uuid': '87a0f0e5-7ebd-390d-a58d-2e22605357cc'},
          {'link': 'https://finance.yahoo.com/news/cosmo-bring-real-time-ai-050200583.html',
           'providerPublishTime': 1717390920,
           'publisher': 'Newsfile',
           'relatedTickers': ['CMOPF'],
           'title': 'Cosmo to Bring Real-Time AI into Intelligent Medical '
                    'Devices with NVIDIA IGX',
           'type': 'STORY',
           'uuid': '0ccd689d-f2c2-3863-bc7e-9f7e149e5209'},
          {'link': 'https://finance.yahoo.com/news/formosa-laboratories-completes-acquisition-synchem-050100973.html',
           'providerPublishTime': 1717390860,
           'publisher': 'PR Newswire',
           'thumbnail': {'resolutions': [{'height': 16,
                                          'tag': 'original',
                                          'url': 'https://s.yimg.com/uu/api/res/1.2/C5YjYIGSs0oai2fzZGJL5w--~B/aD0xNjt3PTE2O2FwcGlkPXl0YWNoeW9u/https://media.zenfs.com/en/prnewswire.com/f2c7aa95a346d7cd28e0120b7e61e4c6',
                                          'width': 16},
                                         {'height': 140,
                                          'tag': '140x140',
                                          'url': 'https://s.yimg.com/uu/api/res/1.2/dy5WZBH1sCwBZhngOOveZw--~B/Zmk9ZmlsbDtoPTE0MDtweW9mZj0wO3c9MTQwO2FwcGlkPXl0YWNoeW9u/https://media.zenfs.com/en/prnewswire.com/f2c7aa95a346d7cd28e0120b7e61e4c6',
                                          'width': 140}]},
           'title': 'Formosa Laboratories Completes the Acquisition of Synchem '
                    'to Expand North American CDMO Footprint',
           'type': 'STORY',
           'uuid': '2469b825-9891-3edd-9117-bd53abbc27b4'},
          {'link': 'https://finance.yahoo.com/news/alk-presents-positive-phase-3-050000824.html',
           'providerPublishTime': 1717390800,
           'publisher': 'GlobeNewswire',
           'relatedTickers': ['AKBLF'],
           'thumbnail': {'resolutions': [{'height': 39,
                                          'tag': 'original',
                                          'url': 'https://s.yimg.com/uu/api/res/1.2/TFRWuPjwySPHeuzcZu7baA--~B/aD0zOTt3PTE0MjthcHBpZD15dGFjaHlvbg--/https://media.zenfs.com/en/globenewswire.com/848fac2aa05860966f3ec6e476ae2174',
                                          'width': 142},
                                         {'height': 140,
                                          'tag': '140x140',
                                          'url': 'https://s.yimg.com/uu/api/res/1.2/ThuNbcPP_Feh2fkyTF1kLA--~B/Zmk9ZmlsbDtoPTE0MDtweW9mZj0wO3c9MTQwO2FwcGlkPXl0YWNoeW9u/https://media.zenfs.com/en/globenewswire.com/848fac2aa05860966f3ec6e476ae2174',
                                          'width': 140}]},
           'title': 'ALK presents positive phase 3 paediatric trial data '
                    'offering new hope for children with respiratory allergies',
           'type': 'STORY',
           'uuid': '03b1801d-740e-3e3c-8e32-35ae99f88f74'},
          {'link': 'https://finance.yahoo.com/news/uae-host-games-future-2025-050000491.html',
           'providerPublishTime': 1717390800,
           'publisher': 'PR Newswire',
           'thumbnail': {'resolutions': [{'height': 267,
                                          'tag': 'original',
                                          'url': 'https://s.yimg.com/uu/api/res/1.2/OSxSsuhRfOm.xhRvI8EnDA--~B/aD0yNjc7dz00MDA7YXBwaWQ9eXRhY2h5b24-/https://media.zenfs.com/en/prnewswire.com/787202b2246b38029f0bbe86ecc77e2e',
                                          'width': 400},
                                         {'height': 140,
                                          'tag': '140x140',
                                          'url': 'https://s.yimg.com/uu/api/res/1.2/JPxiXY91JZUYybL6Xz9.8A--~B/Zmk9ZmlsbDtoPTE0MDtweW9mZj0wO3c9MTQwO2FwcGlkPXl0YWNoeW9u/https://media.zenfs.com/en/prnewswire.com/787202b2246b38029f0bbe86ecc77e2e',
                                          'width': 140}]},
           'title': 'UAE TO HOST GAMES OF THE FUTURE 2025',
           'type': 'STORY',
           'uuid': '160df24c-fc26-34ce-9879-09c29aa5bc1c'},
          {'link': 'https://finance.yahoo.com/news/start-day-message-050000714.html',
           'providerPublishTime': 1717390800,
           'publisher': 'GlobeNewswire',
           'title': 'Start of Day Message',
           'type': 'STORY',
           'uuid': '218e0d81-069c-3803-b0db-d14c1cffe14d'}],
 'quotes': [{'exchDisp': 'Frankfurt',
             'exchange': 'FRA',
             'index': 'quotes',
             'industry': 'Gold',
             'industryDisp': 'Gold',
             'isYahooFinance': True,
             'longname': 'Asante Gold Corporation',
             'quoteType': 'EQUITY',
             'score': 2000100.0,
             'sector': 'Basic Materials',
             'sectorDisp': 'Basic Materials',
             'shortname': 'ASANTE GOLD CORP.',
             'symbol': '1A9.F',
             'typeDisp': 'Equity'}],
 'researchReports': [],
 'screenerFieldResults': [],
 'timeTakenForAlgowatchlist': 400,
 'timeTakenForCrunchbase': 0,
 'timeTakenForCulturalAssets': 0,
 'timeTakenForNav': 400,
 'timeTakenForNews': 700,
 'timeTakenForPredefinedScreener': 400,
 'timeTakenForQuotes': 428,
 'timeTakenForResearchReports': 0,
 'timeTakenForScreenerField': 0,
 'totalTime': 37}

yfinance version

0.2.40

Python version

3.10

Operating system

Windows

abrohit commented 4 weeks ago

I see this issue as well.

import yfinance as yf

stock = yf.Ticker("TVSMOTOR.NS")
news = stock.news

print(news)

Returns "random" news or news from the main page.

Edit: Making the raw API call also returns the same faulty news. Looks like the error stems from the URL endpoint.

lkaino commented 3 weeks ago

Same issue, hopefully they will fix the endpoint soon

jamesdidit72 commented 1 week ago

straight up doesnt work now? raise RequestsJSONDecodeError(e.msg, e.doc, e.pos) requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

lkaino commented 1 week ago

straight up doesnt work now? raise RequestsJSONDecodeError(e.msg, e.doc, e.pos) requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Yes, had that yesterday. Today it worked for a while and now it is giving this error again.