Skip to content

equity_history() fails with KeyError: 'data' - NSE API endpoint returns 404 #74

Closed

Description

@AJ

Summary

The equity_history() function in nsepython fails because NSE has removed their free historical equity data API endpoint. The endpoint /api/historical/cm/equity now returns HTTP 404 (Resource not found).

Environment

  • NSEPython Version: 2.97 (latest)
  • Python Version: 3.13
  • Operating System: Windows 11
  • Date: January 8, 2026

Steps to Reproduce

from nsepython import equity_history

This call fails with KeyError: 'data'

result = equity_history('SBIN', 'EQ', '01-12-2025', '08-12-2025')

Actual Behavior

Traceback (most recent call last):
File "rahu.py", line 580, in equity_history_virgin
return pd.DataFrame.from_records(payload["data"])
~~~~~~~^^^^^^^^
KeyError: 'data'

Root Cause:

The URL https://www.nseindia.com/api/historical/cm/equity?symbol=SBIN&series=["EQ"]&from=01-12-2025&to=08-12-2025 returns HTTP 404 with HTML response:

<title>Resource not found</title> Resource not found

The nsefetch() function catches the JSONDecodeError and returns {} (empty dict), which then causes payload["data"] to raise KeyError.

Expected Behavior

Either:

  • The function should return an empty DataFrame with a clear warning message
  • Or throw a more descriptive exception explaining the API is no longer available

Additional Context

What Still Works:

  • index_history() for NIFTY 50, SENSEX, etc. works perfectly
  • The endpoint /api/chart-databyindex for indices is still active

What's Broken:

  • /api/historical/cm/equity endpoint for equity historical data (returns 404)

Activity

  1. TEJ2401 commented on Jan 17, 2026

    @TEJ2401

    The API for example as below :
    https://www.nseindia.com/api/historical/cm/equity?symbol=INFY&series=[%22EQ%22]&from=01-01-2025&to=31-12-2025.
    is no longer valid as it says Resource not found

  2. aeron7 commented on Mar 7, 2026

    @aeron7
    Owner

    Fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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