Error fetching historical data v3 api

What is the reason of this error. happening randomly

2025-04-29 12:35:13,776 [ERROR] Historical fetch failed for BANDHANBNK on 2025-04-28: Cannot connect to host api.upstox.com:443 ssl:default [[SSL: DECRYPTION_FAILED_OR_BAD_RECORD_MAC] decryption failed or bad record mac (_ssl.c:1028)]
2025-04-29 12:57:49,405 [ERROR] Historical fetch failed for BANDHANBNK on 2025-04-28: Cannot connect to host api.upstox.com:443 ssl:default [[SSL: DECRYPTION_FAILED_OR_BAD_RECORD_MAC] decryption failed or bad record mac (_ssl.c:1028)]
2025-04-29 13:30:28,730 [ERROR] Historical fetch failed for IEX on 2025-04-28: Cannot connect to host api.upstox.com:443 ssl:default [[SSL: DECRYPTION_FAILED_OR_BAD_RECORD_MAC] decryption failed or bad record mac (_ssl.c:1028)]
2025-04-29 13:55:35,330 [ERROR] Historical fetch failed for CDSL on 2025-04-28: Cannot connect to host api.upstox.com:443 ssl:default [[SSL: DECRYPTION_FAILED_OR_BAD_RECORD_MAC] decryption failed or bad record mac (_ssl.c:1028)]

@gaurav Could you please share the request details and the time at which you encountered this error ?

@Anand_Sajankar Sir,
Exact time with dt hhmmss mentioned in the log

@gaurav Could you please share the request details (URL, request params etc.) for further investigation ?

@Anand_Sajankar plz see if this helps,

**Request Details**:
- **URL**: `https://api.upstox.com/v3/historical-candle/NSE_EQ|BANDHANBNK/days/1/2025-04-28/2025-04-28`
- **Headers**:
  ```json
  {
    "Authorization": "Bearer [REDACTED]",
    "x-api-key": "[REDACTED]",
    "Accept": "application/json"
  }

Parameters (in URL path):
instrument_key: NSE_EQ|BANDHANBNK (similarly NSE_EQ|IEX, NSE_EQ|CDSL)
interval: days/1
to_date: 2025-04-28
from_date: 2025-04-28
Method: GET

@gaurav It seems you’re using an incorrect instrument key. The instrument key is a combination of the segment and the ISIN.

For example, the instrument key for BANDHANBNK is: NSE_EQ|INE545U01014

You can try the following URL, which should work:
https://api.upstox.com/v3/historical-candle/NSE_EQ%7CINE545U01014/days/1/2025-04-28/2025-04-28

To find the correct instrument key for any trading symbol, refer to the instrument JSON file here:

Sorry @Anand_Sajankar I think I gave you wrong instrument key url. I confirm that I am already using url as suggested by you. I am fetching historical for around 215 stocks and problem occurs only in some stocks just randomly as u can see in today’s log

2025-05-05 09:21:49,778 [ERROR] Historical fetch failed for ABCAPITAL: Cannot connect to host api.upstox.com:443 ssl:default [[SSL: DECRYPTION_FAILED_OR_BAD_RECORD_MAC] decryption failed or bad record mac (_ssl.c:1028)]
2025-05-05 09:21:49,778 [ERROR] Historical fetch failed for ABCAPITAL: Cannot connect to host api.upstox.com:443 ssl:default [[SSL: DECRYPTION_FAILED_OR_BAD_RECORD_MAC] decryption failed or bad record mac (_ssl.c:1028)]
2025-05-05 09:41:55,553 [ERROR] Historical fetch failed for BAJAJ-AUTO: Cannot connect to host api.upstox.com:443 ssl:default [[SSL: DECRYPTION_FAILED_OR_BAD_RECORD_MAC] decryption failed or bad record mac (_ssl.c:1028)]
2025-05-05 09:41:55,553 [ERROR] Historical fetch failed for BAJAJ-AUTO: Cannot connect to host api.upstox.com:443 ssl:default [[SSL: DECRYPTION_FAILED_OR_BAD_RECORD_MAC] decryption failed or bad record mac (_ssl.c:1028)]
2025-05-05 09:49:09,147 [ERROR] Historical fetch failed for DABUR: Response payload is not completed: <TransferEncodingError: 400, message=‘Not enough data for satisfy transfer length header.’>. SSLError(1, ‘[SSL: DECRYPTION_FAILED_OR_BAD_RECORD_MAC] decryption failed or bad record mac (_ssl.c:2648)’)
2025-05-05 09:49:09,147 [ERROR] Historical fetch failed for DABUR: Response payload is not completed: <TransferEncodingError: 400, message=‘Not enough data for satisfy transfer length header.’>. SSLError(1, ‘[SSL: DECRYPTION_FAILED_OR_BAD_RECORD_MAC] decryption failed or bad record mac (_ssl.c:2648)’)
2025-05-05 10:11:55,154 [ERROR] Historical fetch failed for GMRAIRPORT: Cannot connect to host api.upstox.com:443 ssl:default [[SSL: DECRYPTION_FAILED_OR_BAD_RECORD_MAC] decryption failed or bad record mac (_ssl.c:1028)]
2025-05-05 10:11:55,154 [ERROR] Historical fetch failed for GMRAIRPORT: Cannot connect to host api.upstox.com:443 ssl:default [[SSL: DECRYPTION_FAILED_OR_BAD_RECORD_MAC] decryption failed or bad record mac (_ssl.c:1028)]
2025-05-05 10:22:09,433 [ERROR] Error fetching data (attempt 1): Response payload is not completed: <TransferEncodingError: 400, message=‘Not enough data for satisfy transfer length header.’>. SSLError(1, ‘[SSL: DECRYPTION_FAILED_OR_BAD_RECORD_MAC] decryption failed or bad record mac (_ssl.c:2648)’)
2025-05-05 10:22:09,433 [ERROR] Error fetching data (attempt 1): Response payload is not completed: <TransferEncodingError: 400, message=‘Not enough data for satisfy transfer length header.’>. SSLError(1, ‘[SSL: DECRYPTION_FAILED_OR_BAD_RECORD_MAC] decryption failed or bad record mac (_ssl.c:2648)’)

@gaurav This is not a server-side issue; it appears to be related to the client environment. The error is likely caused by network instability leading to corrupted SSL packets. Please check your internet connection, try switching to a different or wired network, and temporarily disable any VPN or proxy if you’re using one.

If you are still getting the same issue, please do share your code for further investigation.

Thanks

1 Like