3333from os .path import abspath
3434from zipfile import ZipFile
3535
36- from comet_ml import API
37- from comet_ml .comet import format_url
36+ from comet_ml import API , get_comet_api_client
3837from comet_ml .config import get_api_key , get_config
39- from comet_ml .connection import Reporting , get_comet_api_client , url_join
38+ from comet_ml .connection import Reporting
4039from comet_ml .exceptions import CometRestApiException
4140from comet_ml .offline import upload_single_offline_experiment
41+ from comet_ml .utils import merge_url , url_join
4242from mlflow .entities .run_tag import RunTag
43+ from mlflow .exceptions import RestException
4344from mlflow .tracking import _get_store
4445from mlflow .tracking ._model_registry .utils import _get_store as get_model_registry_store
4546from mlflow .tracking .registry import UnsupportedModelRegistryStoreURIException
@@ -126,13 +127,40 @@ def __init__(
126127 output_dir = tempfile .mkdtemp ()
127128
128129 # MLFlow conversion
129- self .store = _get_store (mlflow_store_uri )
130+ try :
131+ self .store = _get_store (mlflow_store_uri )
132+ except RestException as e :
133+ if self ._is_authentication_error (e ):
134+ self ._log_authentication_error (
135+ mlflow_store_uri , "connecting to MLflow store"
136+ )
137+ raise
138+ except Exception as e :
139+ if self ._is_authentication_error (e ):
140+ self ._log_authentication_error (
141+ mlflow_store_uri , "connecting to MLflow store"
142+ )
143+ raise
144+
130145 try :
131146 self .model_registry_store = get_model_registry_store (mlflow_store_uri )
132147 except UnsupportedModelRegistryStoreURIException :
133148 self .model_registry_store = None
134149
135- self .mlflow_experiments = search_mlflow_store_experiments (self .store )
150+ try :
151+ self .mlflow_experiments = search_mlflow_store_experiments (self .store )
152+ except RestException as e :
153+ if self ._is_authentication_error (e ):
154+ self ._log_authentication_error (
155+ mlflow_store_uri , "accessing MLflow experiments"
156+ )
157+ raise
158+ except Exception as e :
159+ if self ._is_authentication_error (e ):
160+ self ._log_authentication_error (
161+ mlflow_store_uri , "accessing MLflow experiments"
162+ )
163+ raise
136164 self .len_experiments = len (self .mlflow_experiments ) # We start counting at 0
137165
138166 self .summary = {
@@ -206,7 +234,7 @@ def prepare(self):
206234 LOGGER .info (
207235 tabulate (
208236 table ,
209- headers = ["MLFlow name:" , "Comet.ml name:" , "Prepared count:" ],
237+ headers = ["MLFlow name:" , "Comet ML name:" , "Prepared count:" ],
210238 tablefmt = "presto" ,
211239 )
212240 )
@@ -217,7 +245,7 @@ def prepare(self):
217245 # Upload or not?
218246 print ("" )
219247 if self .answer is None :
220- upload = input ("Upload prepared data to Comet.ml ? [y/N] " ) in ("Y" , "y" )
248+ upload = input ("Upload prepared data to Comet ML ? [y/N] " ) in ("Y" , "y" )
221249 else :
222250 upload = self .answer
223251 print ("" )
@@ -232,8 +260,8 @@ def prepare(self):
232260
233261 LOGGER .info ("" )
234262 LOGGER .info (
235- """If you need support, you can contact us at http://chat.comet.ml /"""
236- """ or https://comet.ml /docs/quick-start/#getting-support"""
263+ """If you need support, you can contact us at http://chat.comet.com /"""
264+ """ or https://comet.com /docs/quick-start/#getting-support"""
237265 )
238266 LOGGER .info ("" )
239267
@@ -319,11 +347,11 @@ def prepare_single_mlflow_run(self, run, original_experiment_name):
319347 base_url = url_join (
320348 self .api_client .server_url , "/api/experiment/redirect"
321349 )
322- tags ["mlflow.parentRunUrl" ] = format_url (
323- base_url , experimentKey = tags ["mlflow.parentRunId" ]
350+ tags ["mlflow.parentRunUrl" ] = merge_url (
351+ base_url , { " experimentKey" : tags ["mlflow.parentRunId" ]}
324352 )
325353
326- # Save the original MLFlow experiment name too as Comet.ml project might
354+ # Save the original MLFlow experiment name too as Comet.com project might
327355 # get renamed
328356 tags ["mlflow.experimentName" ] = original_experiment_name
329357
@@ -449,7 +477,7 @@ def get_model_prefixes(self, artifact_list):
449477 return models
450478
451479 def upload (self , prepared_data ):
452- LOGGER .info ("# Start uploading data to Comet.ml " )
480+ LOGGER .info ("# Start uploading data to Comet ML " )
453481
454482 all_project_names = []
455483
@@ -494,7 +522,7 @@ def upload(self, prepared_data):
494522
495523 LOGGER .info ("" )
496524 LOGGER .info (
497- "Explore your experiment data on Comet.ml with the following links:" ,
525+ "Explore your experiment data on Comet ML with the following links:" ,
498526 )
499527 if len (all_project_names ) < 6 :
500528 for project_name in all_project_names :
@@ -516,7 +544,7 @@ def upload(self, prepared_data):
516544
517545 LOGGER .info (
518546 "Get deeper instrumentation by adding Comet SDK to your project:"
519- " https://comet.ml /docs/python-sdk/mlflow/"
547+ " https://comet.com /docs/python-sdk/mlflow/"
520548 )
521549 LOGGER .info ("" )
522550
@@ -593,7 +621,7 @@ def get_or_create_comet_project(self, exp):
593621
594622 def create_or_login (self ):
595623 auth_api_client = get_comet_api_client (None )
596- LOGGER .info ("Please create a free Comet account with your email." )
624+ LOGGER .info ("Please create a free Comet.com account with your email." )
597625 if self .email is None :
598626 email = input ("Email: " )
599627 print ("" )
@@ -627,23 +655,23 @@ def create_or_login(self):
627655 Reporting .report ("mlflow_new_user" , api_key = new_account ["apiKey" ])
628656
629657 LOGGER .info (
630- "A Comet.ml account has been created for you and an email was sent to"
658+ "A Comet.com account has been created for you and an email was sent to"
631659 " you to setup your password later."
632660 )
633661 save_api_key (new_account ["apiKey" ])
634662 LOGGER .info (
635- "Your Comet API Key has been saved to ~/.comet.ini , it is also"
636- " available on your Comet.ml dashboard."
663+ "Your Comet API Key has been saved to ~/.comet.config , it is also"
664+ " available on your Comet.com dashboard."
637665 )
638666 return (
639667 new_account ["apiKey" ],
640668 new_account ["token" ],
641669 )
642670 else :
643671 LOGGER .info (
644- "An account already exists for this account , please input your API Key"
672+ "An account already exists for this email , please input your API Key"
645673 " below (you can find it in your Settings page,"
646- " https://comet.ml /docs/quick-start/#getting-your-comet-api-key):"
674+ " https://comet.com /docs/quick-start/#getting-your-comet-api-key):"
647675 )
648676 api_key = input ("API Key: " )
649677
@@ -663,3 +691,46 @@ def get_api_key_or_login(self, api_key):
663691 Reporting .report ("mlflow_existing_user" , api_key = api_key )
664692
665693 return (api_key , None )
694+
695+ def _is_authentication_error (self , exception ):
696+ """Check if an exception is an authentication error (401)."""
697+ error_msg = str (exception )
698+ status_code = None
699+
700+ # Check HTTP status code for RestException
701+ if hasattr (exception , "get_http_status_code" ):
702+ status_code = exception .get_http_status_code ()
703+
704+ return (
705+ status_code == 401
706+ or "401" in error_msg
707+ or "Credential" in error_msg
708+ or "authentication" in error_msg .lower ()
709+ )
710+
711+ def _log_authentication_error (self , mlflow_store_uri , context ):
712+ """Log helpful error message for MLflow authentication errors."""
713+ LOGGER .error ("" )
714+ LOGGER .error ("MLflow authentication error detected when %s." , context )
715+ LOGGER .error ("" )
716+ if mlflow_store_uri and "databricks" in mlflow_store_uri .lower ():
717+ LOGGER .error (
718+ "For Databricks MLflow stores, you need to set the "
719+ "DATABRICKS_TOKEN environment variable:"
720+ )
721+ LOGGER .error (
722+ " export DATABRICKS_TOKEN=your_databricks_personal_access_token"
723+ )
724+ LOGGER .error ("" )
725+ LOGGER .error ("You can generate a token by:" )
726+ LOGGER .error (" 1. Click on your user profile icon in the top-right corner" )
727+ LOGGER .error (" 2. Select 'User Settings'" )
728+ LOGGER .error (" 3. Go to the 'Access Tokens' tab" )
729+ LOGGER .error (" 4. Click 'Generate New Token'" )
730+ else :
731+ LOGGER .error ("For authenticated MLflow stores, you may need to set:" )
732+ LOGGER .error (" - DATABRICKS_TOKEN (for Databricks token-based auth)" )
733+ LOGGER .error (
734+ " - MLFLOW_TRACKING_USERNAME and MLFLOW_TRACKING_PASSWORD (for basic auth)"
735+ )
736+ LOGGER .error ("" )
0 commit comments