<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic error status 400 calling serving model endpoint invocation using personal access token on Azure Databricks in Machine Learning</title>
    <link>https://community.databricks.com/t5/machine-learning/error-status-400-calling-serving-model-endpoint-invocation-using/m-p/16504#M867</link>
    <description>&lt;P&gt;Hi all, I've deployed a model, moved it to production and served it (mlflow), but when testing it in the python notebook I get a 400 error. code/details below:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;import os&lt;/P&gt;&lt;P&gt;import requests&lt;/P&gt;&lt;P&gt;import json&lt;/P&gt;&lt;P&gt;import pandas as pd&lt;/P&gt;&lt;P&gt;import numpy as np&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;# Create two records for testing the prediction&lt;/P&gt;&lt;P&gt;test_input1 = {"OriginAirportCode":"SAT","Month":5,"DayofMonth":5,"CRSDepHour":13,"DayOfWeek":7,"Carrier":"MQ","DestAirportCode":"ORD","WindSpeed":9,"SeaLevelPressure":30.03,"HourlyPrecip":0}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;test_input2 = {"OriginAirportCode":"ATL","Month":2,"DayofMonth":5,"CRSDepHour":8,"DayOfWeek":4,"Carrier":"MQ","DestAirportCode":"MCO","WindSpeed":3,"SeaLevelPressure":31.03,"HourlyPrecip":0}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;# package the inputs into a JSON string and test run() in local notebook&lt;/P&gt;&lt;P&gt;inputs = pd.DataFrame([test_input1, test_input2])&lt;/P&gt;&lt;P&gt;print(inputs)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;def create_tf_serving_json(data):&lt;/P&gt;&lt;P&gt;&amp;nbsp;return {'inputs': {name: data[name].tolist() for name in data.keys()} if isinstance(data, dict) else data.tolist()}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;def score_model(dataset):&lt;/P&gt;&lt;P&gt;&amp;nbsp;url = 'https://adb-&amp;lt;obfuscated&amp;gt;.azuredatabricks.net/model/Delay%20Estimator/Production/invocations' # Enter your URL here&lt;/P&gt;&lt;P&gt;&amp;nbsp;personal_access_token = 'dapi2&amp;lt;obfuscated&amp;gt;853-2' # Enter your Personal Access Token here&lt;/P&gt;&lt;P&gt;&amp;nbsp;headers = {'Authorization': f'Bearer {personal_access_token}'}&lt;/P&gt;&lt;P&gt;&amp;nbsp;data_json = dataset.to_dict(orient='split') if isinstance(dataset, pd.DataFrame) else create_tf_serving_json(dataset)&lt;/P&gt;&lt;P&gt;&amp;nbsp;response = requests.request(method='POST', headers=headers, url=url, json=data_json)&lt;/P&gt;&lt;P&gt;&amp;nbsp;if response.status_code != 200:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;raise Exception(f'Request failed with status {response.status_code}, {response.text}')&lt;/P&gt;&lt;P&gt;&amp;nbsp;return response.json()&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;score_model(inputs)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CMD ERROR OUTPUT:&lt;/P&gt;&lt;P&gt;Exception: Request failed with status 400, {"error_code": "BAD_REQUEST", "message": "The input must be a JSON dictionary with exactly one of the input fields {'dataframe_split', 'instances', 'inputs', 'dataframe_records'}. Received dictionary with input fields: ['index', 'columns', 'data']. IMPORTANT: The MLflow Model scoring protocol has changed in MLflow version 2.0. If you are seeing this error, you are likely using an outdated scoring request format. To resolve the error, either update your request format or adjust your MLflow Model's requirements file to specify an older version of MLflow (for example, change the 'mlflow' requirement specifier to 'mlflow==1.30.0'). If you are making a request using the MLflow client (e.g. via `mlflow.pyfunc.spark_udf()`), upgrade your MLflow client to a version &amp;gt;= 2.0 in order to use the new request format. For more information about the updated MLflow Model scoring protocol in MLflow 2.0, see &lt;A href="https://mlflow.org/docs/latest/models.html#deploy-mlflow-models.&amp;quot;}" target="test_blank"&gt;https://mlflow.org/docs/latest/models.html#deploy-mlflow-models."}&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've tested with earlier library versions with no joy, and also tried different ways to code it. Does anyone have any idea what the issue is or a better way to call it?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'll be calling the same serving endpoint from a web app once this is working.&lt;/P&gt;</description>
    <pubDate>Fri, 16 Dec 2022 09:03:58 GMT</pubDate>
    <dc:creator>Charley</dc:creator>
    <dc:date>2022-12-16T09:03:58Z</dc:date>
    <item>
      <title>error status 400 calling serving model endpoint invocation using personal access token on Azure Databricks</title>
      <link>https://community.databricks.com/t5/machine-learning/error-status-400-calling-serving-model-endpoint-invocation-using/m-p/16504#M867</link>
      <description>&lt;P&gt;Hi all, I've deployed a model, moved it to production and served it (mlflow), but when testing it in the python notebook I get a 400 error. code/details below:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;import os&lt;/P&gt;&lt;P&gt;import requests&lt;/P&gt;&lt;P&gt;import json&lt;/P&gt;&lt;P&gt;import pandas as pd&lt;/P&gt;&lt;P&gt;import numpy as np&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;# Create two records for testing the prediction&lt;/P&gt;&lt;P&gt;test_input1 = {"OriginAirportCode":"SAT","Month":5,"DayofMonth":5,"CRSDepHour":13,"DayOfWeek":7,"Carrier":"MQ","DestAirportCode":"ORD","WindSpeed":9,"SeaLevelPressure":30.03,"HourlyPrecip":0}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;test_input2 = {"OriginAirportCode":"ATL","Month":2,"DayofMonth":5,"CRSDepHour":8,"DayOfWeek":4,"Carrier":"MQ","DestAirportCode":"MCO","WindSpeed":3,"SeaLevelPressure":31.03,"HourlyPrecip":0}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;# package the inputs into a JSON string and test run() in local notebook&lt;/P&gt;&lt;P&gt;inputs = pd.DataFrame([test_input1, test_input2])&lt;/P&gt;&lt;P&gt;print(inputs)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;def create_tf_serving_json(data):&lt;/P&gt;&lt;P&gt;&amp;nbsp;return {'inputs': {name: data[name].tolist() for name in data.keys()} if isinstance(data, dict) else data.tolist()}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;def score_model(dataset):&lt;/P&gt;&lt;P&gt;&amp;nbsp;url = 'https://adb-&amp;lt;obfuscated&amp;gt;.azuredatabricks.net/model/Delay%20Estimator/Production/invocations' # Enter your URL here&lt;/P&gt;&lt;P&gt;&amp;nbsp;personal_access_token = 'dapi2&amp;lt;obfuscated&amp;gt;853-2' # Enter your Personal Access Token here&lt;/P&gt;&lt;P&gt;&amp;nbsp;headers = {'Authorization': f'Bearer {personal_access_token}'}&lt;/P&gt;&lt;P&gt;&amp;nbsp;data_json = dataset.to_dict(orient='split') if isinstance(dataset, pd.DataFrame) else create_tf_serving_json(dataset)&lt;/P&gt;&lt;P&gt;&amp;nbsp;response = requests.request(method='POST', headers=headers, url=url, json=data_json)&lt;/P&gt;&lt;P&gt;&amp;nbsp;if response.status_code != 200:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;raise Exception(f'Request failed with status {response.status_code}, {response.text}')&lt;/P&gt;&lt;P&gt;&amp;nbsp;return response.json()&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;score_model(inputs)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CMD ERROR OUTPUT:&lt;/P&gt;&lt;P&gt;Exception: Request failed with status 400, {"error_code": "BAD_REQUEST", "message": "The input must be a JSON dictionary with exactly one of the input fields {'dataframe_split', 'instances', 'inputs', 'dataframe_records'}. Received dictionary with input fields: ['index', 'columns', 'data']. IMPORTANT: The MLflow Model scoring protocol has changed in MLflow version 2.0. If you are seeing this error, you are likely using an outdated scoring request format. To resolve the error, either update your request format or adjust your MLflow Model's requirements file to specify an older version of MLflow (for example, change the 'mlflow' requirement specifier to 'mlflow==1.30.0'). If you are making a request using the MLflow client (e.g. via `mlflow.pyfunc.spark_udf()`), upgrade your MLflow client to a version &amp;gt;= 2.0 in order to use the new request format. For more information about the updated MLflow Model scoring protocol in MLflow 2.0, see &lt;A href="https://mlflow.org/docs/latest/models.html#deploy-mlflow-models.&amp;quot;}" target="test_blank"&gt;https://mlflow.org/docs/latest/models.html#deploy-mlflow-models."}&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've tested with earlier library versions with no joy, and also tried different ways to code it. Does anyone have any idea what the issue is or a better way to call it?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'll be calling the same serving endpoint from a web app once this is working.&lt;/P&gt;</description>
      <pubDate>Fri, 16 Dec 2022 09:03:58 GMT</pubDate>
      <guid>https://community.databricks.com/t5/machine-learning/error-status-400-calling-serving-model-endpoint-invocation-using/m-p/16504#M867</guid>
      <dc:creator>Charley</dc:creator>
      <dc:date>2022-12-16T09:03:58Z</dc:date>
    </item>
    <item>
      <title>Re: error status 400 calling serving model endpoint invocation using personal access token on Azure Databricks</title>
      <link>https://community.databricks.com/t5/machine-learning/error-status-400-calling-serving-model-endpoint-invocation-using/m-p/16505#M868</link>
      <description>&lt;P&gt;&lt;B&gt;data_json&lt;/B&gt; in the score_model function should be defined as follows&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;ds_dict = {"dataframe_split": dataset.to_dict(orient='split')} if isinstance(dataset, pd.DataFrame) else create_tf_serving_json(dataset)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Feb 2023 13:02:54 GMT</pubDate>
      <guid>https://community.databricks.com/t5/machine-learning/error-status-400-calling-serving-model-endpoint-invocation-using/m-p/16505#M868</guid>
      <dc:creator>nakany</dc:creator>
      <dc:date>2023-02-07T13:02:54Z</dc:date>
    </item>
  </channel>
</rss>

