'in mlflow under Python, get_latest_versions method fails with "405 Method Not Allowed", but get_model_version method works fine
For mlflow, when I use get_model_version(model_name, model_version) method it works fine, but get_latest_versions method fails as shown below. The same model that I am able to get by its version number also has assigned stage 'Production' but I can't get it by specifying this stage. On my client side I have mlflow 1.24.0 (tried 1.23.0 and 1.23.1 too) under Python 3.9.7 (tried 3.8.8 too) on Windows 10. I believe the server uses mlflow 1.18.
import mlflow
from mlflow.tracking import MlflowClient
...
mlflow.set_tracking_uri('https://fs-mlflow-dev.whatever.whatever.com/')
...
client = MlflowClient()
model_stage='Production'
_vers = client.get_latest_versions(model_name, [model_stage])
Traceback (most recent call last):
File "C:\Users\926304897\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Users\926304897\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "C:\Users\926304897\Documents\GitHub\CreditModeling\src\models\test_decision.py", line 92, in <module>
main(confidence_interval=conf_int)
File "C:\Users\926304897\Documents\GitHub\CreditModeling\src\models\test_decision.py", line 54, in main
cdm.load_model( model_stage=LOAD_STAGE)#model_version=27 )
File "C:\Users\926304897\Documents\GitHub\CreditModeling\src\models\decision_model.py", line 1128, in load_model
_vers = client.get_latest_versions(model_name, [model_stage])
File "C:\Users\926304897\AppData\Local\JetBrains\PyCharmCE2021.3\demo\PyCharmLearningProject\venv\lib\site-packages\mlflow\tracking\client.py", line 2048, in get_latest_versions
return self._get_registry_client().get_latest_versions(name, stages)
File "C:\Users\926304897\AppData\Local\JetBrains\PyCharmCE2021.3\demo\PyCharmLearningProject\venv\lib\site-packages\mlflow\tracking\_model_registry\client.py", line 149, in get_latest_v
ersions
return self.store.get_latest_versions(name, stages)
File "C:\Users\926304897\AppData\Local\JetBrains\PyCharmCE2021.3\demo\PyCharmLearningProject\venv\lib\site-packages\mlflow\store\model_registry\rest_store.py", line 197, in get_latest_v
ersions
response_proto = self._call_endpoint(GetLatestVersions, req_body, call_all_endpoints=True)
File "C:\Users\926304897\AppData\Local\JetBrains\PyCharmCE2021.3\demo\PyCharmLearningProject\venv\lib\site-packages\mlflow\store\model_registry\rest_store.py", line 61, in _call_endpoin
t
return call_endpoints(self.get_host_creds(), endpoints, json_body, response_proto)
File "C:\Users\926304897\AppData\Local\JetBrains\PyCharmCE2021.3\demo\PyCharmLearningProject\venv\lib\site-packages\mlflow\utils\rest_utils.py", line 251, in call_endpoints
return call_endpoint(host_creds, endpoint, method, json_body, response_proto)
File "C:\Users\926304897\AppData\Local\JetBrains\PyCharmCE2021.3\demo\PyCharmLearningProject\venv\lib\site-packages\mlflow\utils\rest_utils.py", line 240, in call_endpoint
response = verify_rest_response(response, endpoint)
File "C:\Users\926304897\AppData\Local\JetBrains\PyCharmCE2021.3\demo\PyCharmLearningProject\venv\lib\site-packages\mlflow\utils\rest_utils.py", line 175, in verify_rest_response
raise MlflowException("%s. Response body: '%s'" % (base_msg, response.text))
mlflow.exceptions.MlflowException: API request to endpoint /api/2.0/mlflow/registered-models/get-latest-versions failed with error code 405 != 200. Response body: '<!DOCTYPE HTML PUBLIC "
-//W3C//DTD HTML 3.2 Final//EN">
<title>405 Method Not Allowed</title>
<h1>Method Not Allowed</h1>
<p>The method is not allowed for the requested URL.</p>
Solution 1:[1]
I had this same problem running MLFlow client as 1.23.1 and noticed the server was at 1.14. I upgraded the server to 1.26 and the problem went away.
I have a model registered as TestModel (v1) and flagged as Production.
I have an S3 back-end with credentials set as ENV vars along with the following: MLFLOW_ARTIFACT_LOCATION MLFLOW_S3_ENDPOINT_URL MLFLOW_TRACKING_URI
import mlflow
model = mlflow.pyfunc.load_model(model_uri="models:/TestModel/1") # Works
model = mlflow.pyfunc.load_model(model_uri="models:/TestModel/Production") # Works
model = mlflow.pyfunc.load_model(model_uri="models:/TestModel/Staging") # Fails as expected with:
# mlflow.exceptions.MlflowException: No versions of model with name 'TestModel' and stage 'Staging' found
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Eric McDonald |