Skip to content

Update Yahoo Finance API Authentication#4

Merged
fleveque merged 2 commits into
mainfrom
feature/api-update
Jan 27, 2026
Merged

Update Yahoo Finance API Authentication#4
fleveque merged 2 commits into
mainfrom
feature/api-update

Conversation

@fleveque

Copy link
Copy Markdown
Owner

Problem

The current implementation uses a cookie/crumb authentication flow that Yahoo Finance tightened in mid-2023:

  • Cookies now expire faster (often within minutes)
  • Crumb extraction from /v1/test/getcrumb endpoint may fail
  • "Invalid Cookie" and "Invalid Crumb" errors are common

Research Summary

Sources:

Working approaches from other libraries:

  1. Basic strategy (current): fc.yahoo.com cookie + getcrumb - may still work with proper session persistence
  2. Homepage scraping: Visit finance.yahoo.com, extract crumb via regex "crumb":"([^"]+)"
  3. Alternative domain: Use query2.finance.yahoo.com instead of query1

Solution

Implement multi-strategy authentication with fallback mechanisms while maintaining backwards compatibility.

fleveque and others added 2 commits January 27, 2026 06:16
Yahoo Finance tightened their cookie/crumb authentication in mid-2023,
causing frequent "Invalid Cookie" and "Invalid Crumb" errors. This update
implements a more robust authentication system:

- Add Session singleton class with 60-second TTL for cookie/crumb
- Implement three fallback authentication strategies:
  1. fc.yahoo.com cookie + query1 crumb endpoint
  2. Homepage scraping for embedded crumb
  3. fc.yahoo.com cookie + query2 crumb endpoint
- Add retry logic (max 2 retries) on auth errors with session refresh
- Add custom error classes (AuthenticationError, RateLimitError)
- Remove debug pp statement from stock.rb

Bumps version to 0.2.0. Public API remains unchanged.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@fleveque fleveque merged commit 0aea6cf into main Jan 27, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant