Skip to content

Fix misleading "Invalid credentials" error when requested data is not available#660

Open
AlexCatarino wants to merge 2 commits into
QuantConnect:masterfrom
AlexCatarino:bug-misleading-invalid-credentials-on-data-list
Open

Fix misleading "Invalid credentials" error when requested data is not available#660
AlexCatarino wants to merge 2 commits into
QuantConnect:masterfrom
AlexCatarino:bug-misleading-invalid-credentials-on-data-list

Conversation

@AlexCatarino

@AlexCatarino AlexCatarino commented Jul 24, 2026

Copy link
Copy Markdown
Member

Description

When lean data download requests a data path that is not available, e.g.:

lean data download --dataset "FOREX Data" --data-type Bulk --resolution Second --start 20250101 --end 20260101

the data/list API endpoint responds with status code 500 and an empty body:

--> POST https://www.quantconnect.com/api/v2/data/list with data:
{
    "filePath": "setup/forex/oanda/202"
}
Request was not successful, status code 500, empty body

The API client maps any 500 response to an AuthenticationError, so the user sees Invalid credentials, please log in using 'lean login' — misleading, since the credentials are valid (earlier authenticated requests in the download flow such as data/prices have already succeeded by the time data/list is called).

This PR catches that error in DataClient.list_files and raises a clear message instead:

Error: The requested data with prefix 'setup/forex/oanda/202' is not available, please contact support@quantconnect.com

The response is now attached to AuthenticationError when it is inferred from a 500 status code, so list_files only replaces the message in that case — an AuthenticationError caused by genuinely invalid credentials (hash mismatch) is re-raised unchanged. Other failures are untouched: success: false responses keep the API's own error text, and other status codes keep the generic request-failed message.

Testing

Simulated all data/list failure modes through the real APIClient/DataClient with a mocked HTTP layer:

Scenario Message shown to the user
500, empty body The requested data with prefix '...' is not available, please contact support@quantconnect.com
Hash mismatch (bad credentials) Invalid credentials, please log in using 'lean login' (unchanged)
success: false with API error text API's own message, e.g. Directory not found: ... (unchanged)
Other status codes (400, 502, ...) POST request to .../data/list failed with status code ... (unchanged)

Added unit tests covering the first two rows. No open issues were found tracking this.

🤖 Generated with Claude Code

AlexCatarino and others added 2 commits July 24, 2026 16:15
When `lean data download` requests a data path that is not available,
the data/list API endpoint responds with a 500 status code and an empty
body, which the API client translates into an AuthenticationError with
the message "Invalid credentials, please log in using `lean login`".

This is misleading since the credentials are valid: earlier requests in
the download flow (data/prices, organization lookups) have already
succeeded by the time data/list is called. Catch the error in
DataClient.list_files and raise a clear message telling the user the
requested data is not available and to contact support@quantconnect.com.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Attach the response to AuthenticationError when it is inferred from an
HTTP 500 status code, so DataClient.list_files can distinguish the
"data not available" case from genuinely invalid credentials (hash
mismatch) and only replace the message for the former.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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