Skip to content

[ENH] Add OpenMLAuthenticationError and improve Error Message When API Key is Invalid #1562

@SimonBlanke

Description

@SimonBlanke

Just a minor thing: Errors for authentication and authorization is currently both handled by OpenMLNotAuthorizedError. Here is the difference:

Concept Question Example
Authentication "Who are you?" No API key, invalid key, expired key
Authorization "Are you allowed?" Valid key, but you didn't upload this resource

So we could handle this case with a new error-class: https://github.com/openml/openml-python/blob/main/openml/_api_calls.py#L520
I would suggest a new class called OpenMLAuthenticationError that gives the user more information when the API key is invalid. It could look somewhat like this:

class OpenMLAuthenticationError(...):
    """Exception raised when API authentication fails.

    This typically occurs when:
    - No API key is configured
    - The API key is invalid or expired
    - The API key lacks permissions for the requested operation
    - ...
    """

    def __init__(self, message: str):
        help_text = (
            "\n\nTo fix this:\n"
            "Get your API key at ...\n"
            "Run ... to configure apikey\n"
        )
        super().__init__(message + help_text)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions