File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2424
2525from .__version__ import __version__
2626from .exceptions import (
27+ OpenMLAuthenticationError ,
2728 OpenMLHashException ,
28- OpenMLNotAuthorizedError ,
2929 OpenMLServerError ,
3030 OpenMLServerException ,
3131 OpenMLServerNoResult ,
@@ -518,11 +518,7 @@ def __parse_server_exception(
518518 400 , # run/42 delete
519519 460 , # task/42 delete
520520 ]:
521- msg = (
522- f"The API call { url } requires authentication via an API key.\n Please configure "
523- "OpenML-Python to use your API as described in this example:"
524- "\n https://openml.github.io/openml-python/latest/examples/Basics/introduction_tutorial/#authentication"
525- )
526- return OpenMLNotAuthorizedError (message = msg )
521+ msg = f"The API call { url } requires authentication via an API key."
522+ return OpenMLAuthenticationError (message = msg )
527523
528524 return OpenMLServerException (code = code , message = full_message , url = url )
Original file line number Diff line number Diff line change @@ -63,5 +63,28 @@ class OpenMLNotAuthorizedError(OpenMLServerError):
6363 """Indicates an authenticated user is not authorized to execute the requested action."""
6464
6565
66+ class OpenMLAuthenticationError (OpenMLServerError ):
67+ """Exception raised when API authentication fails.
68+
69+ This typically occurs when:
70+ - No API key is configured
71+ - The API key is invalid or expired
72+ - The API key format is incorrect
73+
74+ This is different from authorization (OpenMLNotAuthorizedError), which occurs
75+ when a valid API key lacks permissions for the requested operation.
76+ """
77+
78+ def __init__ (self , message : str ):
79+ help_text = (
80+ "\n \n To fix this:\n "
81+ "1. Get your API key from https://www.openml.org/\n "
82+ " (you'll need to register for a free account if you don't have one)\n "
83+ "2. Configure your API key by following the authentication guide:\n "
84+ " https://openml.github.io/openml-python/latest/examples/Basics/introduction_tutorial/#authentication"
85+ )
86+ super ().__init__ (message + help_text )
87+
88+
6689class ObjectNotPublishedError (PyOpenMLError ):
6790 """Indicates an object has not been published yet."""
Original file line number Diff line number Diff line change @@ -426,6 +426,9 @@ def get_task(
426426 # Including class labels as part of task meta data handles
427427 # the case where data download was initially disabled
428428 if isinstance (task , (OpenMLClassificationTask , OpenMLLearningCurveTask )):
429+ assert task .target_name is not None , (
430+ "Supervised tasks must define a target feature before retrieving class labels."
431+ )
429432 task .class_labels = dataset .retrieve_class_labels (task .target_name )
430433 # Clustering tasks do not have class labels
431434 # and do not offer download_split
@@ -599,6 +602,7 @@ def create_task(
599602 )
600603
601604 return task_cls (
605+ task_id = None ,
602606 task_type_id = task_type ,
603607 task_type = "None" , # TODO: refactor to get task type string from ID.
604608 data_set_id = dataset_id ,
You can’t perform that action at this time.
0 commit comments