Skip to content

Crumb issue causing connection error #2404

Description

@whitej125

Describe bug

Fresh new install (0.2.55) and first time using yfinance... though I've manually used Yahoo data in the past. So this isn't a rate limit, etc issue.

Can't get the most basic of queries to work. Responses from Yahoo under the hood are:

{"finance":{"result":null,"error":{"code":"Unauthorized","description":"Invalid Crumb"}}}

Simple code that reproduces your problem

yf.enable_debug_mode()
dat = yf.Ticker("MSFT")
dat.info

Debug log from yf.enable_debug_mode()

DEBUG    get_raw_json(): https://query2.finance.yahoo.com/v10/finance/quoteSummary/MSFT
DEBUG    Entering get()
DEBUG     Entering _make_request()
DEBUG      url=https://query2.finance.yahoo.com/v10/finance/quoteSummary/MSFT
DEBUG      params={'modules': 'financialData,quoteType,defaultKeyStatistics,assetProfile,summaryDetail', 'corsDomain': 'finance.yahoo.com', 'formatted': 'false', 'symbol': 'MSFT'}
DEBUG      Entering _get_cookie_and_crumb()
DEBUG       cookie_mode = 'basic'
DEBUG       Entering _get_cookie_and_crumb_basic()

---------------------------------------------------------------------------
ConnectionRefusedError                    Traceback (most recent call last)
File [~/src/shared-notebooks/.venv/lib/python3.11/site-packages/urllib3/connection.py:199](http://localhost:8888/lab/tree/jwhitehead/fin/~/src/shared-notebooks/.venv/lib/python3.11/site-packages/urllib3/connection.py#line=198), in HTTPConnection._new_conn(self)
    198 try:
--> 199     sock = connection.create_connection(
    200         (self._dns_host, self.port),
    201         self.timeout,
    202         source_address=self.source_address,
    203         socket_options=self.socket_options,
    204     )
    205 except socket.gaierror as e:

File [~/src/shared-notebooks/.venv/lib/python3.11/site-packages/urllib3/util/connection.py:85](http://localhost:8888/lab/tree/jwhitehead/fin/~/src/shared-notebooks/.venv/lib/python3.11/site-packages/urllib3/util/connection.py#line=84), in create_connection(address, timeout, source_address, socket_options)
     84 try:
---> 85     raise err
     86 finally:
     87     # Break explicitly a reference cycle

File [~/src/shared-notebooks/.venv/lib/python3.11/site-packages/urllib3/util/connection.py:73](http://localhost:8888/lab/tree/jwhitehead/fin/~/src/shared-notebooks/.venv/lib/python3.11/site-packages/urllib3/util/connection.py#line=72), in create_connection(address, timeout, source_address, socket_options)
     72     sock.bind(source_address)
---> 73 sock.connect(sa)
     74 # Break explicitly a reference cycle

ConnectionRefusedError: [Errno 61] Connection refused

Bad data proof

No response

yfinance version

0.2.55

Python version

3.11.11

Operating system

MacOS

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions