3

I am able to create ml model server using following command

mlflow models serve -m file:///C:/Users/SawarkarFamily/Desktop/mlflow-master/examples/sklearn_elasticnet_wine/mlruns/0/9aeb7ba16d7e4c20870b664e267524ea/artifacts/model -p 8000
2020/07/28 17:10:59 INFO mlflow.models.cli: Selected backend for flavor 'python_function'
2020/07/28 17:11:03 INFO mlflow.pyfunc.backend: === Running command 'conda activate mlflow-76d7aedf36021b9bb7f176264305cf2b7868ca8d & waitress-serve --host=127.0.0.1 --port=8000 --ident=mlflow mlflow.pyfunc.scoring_server.wsgi:app'
c:\users\sawarkarfamily\anaconda3\envs\mlflow-76d7aedf36021b9bb7f176264305cf2b7868ca8d\lib\site-packages\waitress\adjustments.py:441: DeprecationWarning: In future versions of Waitress clear_untrusted_proxy_headers will be set to True by default. You may opt-out by setting this value to False, or opt-in explicitly by setting this to True.
  warnings.warn(
Serving on http://DESKTOP-AO59MJC:8000

In documentation it is given that send that for prediction using curl command as follows:

curl -X POST -H "Content-Type:application/json; format=pandas-split" --data '{"columns":["alcohol", "chlorides", "citric acid", "density", "fixed acidity", "free sulfur dioxide", "pH", "residual sugar", "sulphates", "total sulfur dioxide", "volatile acidity"],"data":[[12.8, 0.029, 0.48, 0.98, 6.2, 29, 3.33, 1.2, 0.39, 75, 0.66]]}' http://127.0.0.1:1234/invocations

I replaced port number with 8000, but getting error.

curl: (6) Could not resolve host: chlorides,
curl: (6) Could not resolve host: citric acid,
curl: (6) Could not resolve host: density,
curl: (6) Could not resolve host: fixed acidity,
curl: (6) Could not resolve host: free sulfur dioxide,
curl: (6) Could not resolve host: pH,
curl: (6) Could not resolve host: residual sugar,
curl: (6) Could not resolve host: sulphates,
curl: (6) Could not resolve host: total sulfur dioxide,
curl: (3) [globbing] unmatched close brace/bracket in column 17
curl: (6) Could not resolve host: 0.029,
curl: (6) Could not resolve host: 0.48,
curl: (6) Could not resolve host: 0.98,
curl: (6) Could not resolve host: 6.2,
curl: (6) Could not resolve host: 29,
curl: (6) Could not resolve host: 3.33,
curl: (6) Could not resolve host: 1.2,
curl: (6) Could not resolve host: 0.39,
curl: (6) Could not resolve host: 75,
curl: (3) [globbing] unmatched close brace/bracket in column 5
{"error_code": "MALFORMED_REQUEST", "message": "Failed to parse input as a Pandas DataFrame. Ensure that the input is a valid JSON-formatted Pandas DataFrame with the `split` orient produced using the `pandas.DataFrame.to_json(..., orient='split')` method.", "stack_trace": "Traceback (most recent call last):\n  File \"c:\\users\\sawarkarfamily\\anaconda3\\envs\\mlflow-76d7aedf36021b9bb7f176264305cf2b7868ca8d\\lib\\site-packages\\mlflow\\pyfunc\\scoring_server\\__init__.py\", line 74, in parse_json_input\n    return _dataframe_from_json(json_input, pandas_orient=orient, schema=schema)\n  File \"c:\\users\\sawarkarfamily\\anaconda3\\envs\\mlflow-76d7aedf36021b9bb7f176264305cf2b7868ca8d\\lib\\site-packages\\mlflow\\utils\\proto_json_utils.py\", line 106, in _dataframe_from_json\n    return pd.read_json(path_or_str, orient=pandas_orient, dtype=False,\n  File \"c:\\users\\sawarkarfamily\\anaconda3\\envs\\mlflow-76d7aedf36021b9bb7f176264305cf2b7868ca8d\\lib\\site-packages\\pandas\\util\\_decorators.py\", line 214, in wrapper\n    return func(*args, **kwargs)\n  File \"c:\\users\\sawarkarfamily\\anaconda3\\envs\\mlflow-76d7aedf36021b9bb7f176264305cf2b7868ca8d\\lib\\site-packages\\pandas\\io\\json\\_json.py\", line 608, in read_json\n    result = json_reader.read()\n  File \"c:\\users\\sawarkarfamily\\anaconda3\\envs\\mlflow-76d7aedf36021b9bb7f176264305cf2b7868ca8d\\lib\\site-packages\\pandas\\io\\json\\_json.py\", line 731, in read\n    obj = self._get_object_parser(self.data)\n  File \"c:\\users\\sawarkarfamily\\anaconda3\\envs\\mlflow-76d7aedf36021b9bb7f176264305cf2b7868ca8d\\lib\\site-packages\\pandas\\io\\json\\_json.py\", line 753, in _get_object_parser\n    obj = FrameParser(json, **kwargs).parse()\n  File \"c:\\users\\sawarkarfamily\\anaconda3\\envs\\mlflow-76d7aedf36021b9bb7f176264305cf2b7868ca8d\\lib\\site-packages\\pandas\\io\\json\\_json.py\", line 857, in parse\n    self._parse_no_numpy()\n  File \"c:\\users\\sawarkarfamily\\anaconda3\\envs\\mlflow-76d7aedf36021b9bb7f176264305cf2b7868ca8d\\lib\\site-packages\\pandas\\io\\json\\_json.py\", line 1094, in _parse_no_numpy\n    for k, v in loads(json, precise_float=self.precise_float).items()\nValueError: Expected object or value\n"}

Kindly someone help me with this.

Rucha
  • 31
  • 2
  • did you ever figure this out? The answers don't understand that this response is coming from the MLflow server, not from CURL itself. I'm now facing this issue and can't figure out what is going on – John Allard Mar 03 '22 at 18:47

2 Answers2

3

your hostname/URI is misplaced in the request

curl -X POST http://127.0.0.1:1234/invocations -H "Content-Type:application/json; format=pandas-split" --data '{"columns":["alcohol", "chlorides", "citric acid", "density", "fixed acidity", "free sulfur dioxide", "pH", "residual sugar", "sulphates", "total sulfur dioxide", "volatile acidity"],"data":[[12.8, 0.029, 0.48, 0.98, 6.2, 29, 3.33, 1.2, 0.39, 75, 0.66]]}' 
Mehdi LAMRANI
  • 11,289
  • 14
  • 88
  • 130
2

I am guessing you ran the curl command in windows command prompt. Command prompt throws error if the data is passed that way in curl. The correct way is to replace single quotes with double quotes and escape all the double quotes in the data like in the below way.

curl -X POST -H "Content-Type:application/json; format=pandas-split" --data "{\"columns\":[\"alcohol\", \"chlorides\", \"citric acid\", \"density\", \"fixed acidity\", \"free sulfur dioxide\", \"pH\", \"residual sugar\", \"sulphates\", \"total sulfur dioxide\", \"volatile acidity\"],\"data\":[[12.8, 0.029, 0.48, 0.98, 6.2, 29, 3.33, 1.2, 0.39, 75, 0.66]]}" http://127.0.0.1:1234/invocations