How to connect to MLFlow tracking server that has auth?
Asked Answered
S

3

5

I want to connect to remote tracking server (http://123.456.78.90) that requires authentication

When I do this:

import mlflow
mlflow.set_tracking_uri("http://123.456.78.90")
mlflow.set_experiment("my-experiment")

I get an error

MlflowException: API request to endpoint /api/2.0/mlflow/experiments/list failed with error code 401 != 200. Response body: 401 Authorization Required

I understand that I need to log in first but I have no idea how to do it

Schofield answered 24/11, 2021 at 15:30 Comment(0)
S
9

MLflow documentation says:

MLFLOW_TRACKING_USERNAME and MLFLOW_TRACKING_PASSWORD - username and password to use with HTTP Basic authentication. To use Basic authentication, you must set both environment variables.

So you just need to set these variables in your code using os.environ:

os.environ['MLFLOW_TRACKING_USERNAME'] = 'name'
os.environ['MLFLOW_TRACKING_PASSWORD'] = 'pass'
Soapstone answered 24/11, 2021 at 17:1 Comment(3)
Thanks, it worked! One more question, if I want to store artifacts in s3, what should I set as a tracking URL? mlflow or aws?Schofield
It's really should be configure on the MLflow server: mlflow.org/docs/latest/…Soapstone
Getting MlflowException: API request to endpoint /api/2.0/mlflow/experiments/list failed with error code 403 != 200Duda
A
1
os.environ['MLFLOW_TRACKING_USERNAME'] = 'name'
os.environ['MLFLOW_TRACKING_PASSWORD'] = 'pass'
os.environ['MLFLOW_TRACKING_URI'] = 'tracking_uri'
Amphichroic answered 20/12, 2023 at 21:54 Comment(0)
H
0

Late to the party, but there is another way (see the MLflow authentication docs) of setting credentials globally (per system user), in the ~/.mlflow/credentials file (in INI format):

[mlflow]
mlflow_tracking_username = username
mlflow_tracking_password = password

This way, you don't have to set the environment variables in each script or your shell config. Any credentials defined in environment variables will override those from the credentials file.

Haze answered 28/3, 2024 at 7:33 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.