Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Model export: {http_status_code": 401} Authentication issue #158

Open
lisanaberberi opened this issue Nov 23, 2023 · 4 comments
Open

Model export: {http_status_code": 401} Authentication issue #158

lisanaberberi opened this issue Nov 23, 2023 · 4 comments

Comments

@lisanaberberi
Copy link

When trying to run export-model command to export a specified model, there is this error:

export-model --model <model_name> --output-dir /tmp/export --versions 1,2

mlflow_export_import.common.MlflowExportImportException: {"message": "{"http_status_code": 401, "uri": "<mlflow_tracking_uri>/api/2.0/mlflow/registered-models/get", "params": {"name": "model_name"}, "response": "You are not authenticated.

already exported the env vars:
export MLFLOW_TRACKING_URI
export MLFLOW_TRACKING_USERNAME
export MLFLOW_TRACKING_PASSWORD

Of course when you use curl and add --user params it's working correctly but not without it:

curl -X GET $MLFLOW_TRACKING_URI/api/2.0/mlflow/registered-models/get?name=$MODEL_NAME --user "$MLFLOW_TRACKING_USERNAME:$MLFLOW_TRACKING_PASSWORD"

@lisanaberberi
Copy link
Author

This applies for the scenario: MLFlow OS --> MLFlow OS

@goncalo-maia
Copy link

I believe mlflow's basic auth use case is not considered when the headers are made in HttpClient class

def _mk_headers(self):
headers = { "User-Agent": USER_AGENT }
if self.token:
headers["Authorization"] = f"Bearer {self.token}"
return headers

By changing the way the get request is sent from:

rsp = requests.get(uri, headers=self._mk_headers(), json=params, timeout=_TIMEOUT)

to rsp = requests.get(uri, auth=(os.environ["MLFLOW_TRACKING_USERNAME"], os.environ["MLFLOW_TRACKING_PASSWORD"]), params=params) the 401 error is no longer present. Of course this breaks the previously implemented auth methods.

I would be willing to contribute a fix for this bug if some guidance on how to best integrate it with the rest is provided.

@lasados
Copy link

lasados commented Apr 13, 2024

Same problem, I fixed it manually in source code

def _mutator(self, method, resource, data=None):

  def _mutator(self, method, resource, data=None):
      uri = self._mk_uri(resource)
      user = os.environ.get('MLFLOW_TRACKING_USERNAME')
      pwd = os.environ.get('MLFLOW_TRACKING_PASSWORD')
      rsp = method(uri, headers=self._mk_headers(), data=data, timeout=_TIMEOUT, auth=(user, pwd))
      return self._check_response(rsp)

@Linnore
Copy link

Linnore commented Jun 7, 2024

Same problem if the tracking server enables authentication. I solved it by using @lasados's answer.

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

No branches or pull requests

4 participants