You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Good work Amir, I am trying to run your code but got the following error, I am using python3 and installed all the requirements. Intial Analysis:
The error is because prediction list contains int64 type values, but jsonifying this list is throwing this error return jsonify({'prediction': prediction}) Suggested fix prediction_str = [str(i) for i in prediction] return jsonify({'prediction': prediction_str})
Converting the int64 list to string array solled the error. Error:
{
"error": "Object of type 'int64' is not JSON serializable",
"trace": "Traceback (most recent call last):\n File "main.py", line 42, in predict\n return jsonify({'prediction': prediction})\n File "C:\Users\vinay\Anaconda3\envs\flask-ml\lib\site-packages\flask\json.py", line 263, in jsonify\n (dumps(data, indent=indent, separators=separators), '\n'),\n File "C:\Users\vinay\Anaconda3\envs\flask-ml\lib\site-packages\flask\json.py", line 123, in dumps\n rv = _json.dumps(obj, **kwargs)\n File "C:\Users\vinay\Anaconda3\envs\flask-ml\lib\json\init.py", line 238, in dumps\n **kw).encode(obj)\n File "C:\Users\vinay\Anaconda3\envs\flask-ml\lib\json\encoder.py", line 201, in encode\n chunks = list(chunks)\n File "C:\Users\vinay\Anaconda3\envs\flask-ml\lib\json\encoder.py", line 430, in _iterencode\n yield from _iterencode_dict(o, _current_indent_level)\n File "C:\Users\vinay\Anaconda3\envs\flask-ml\lib\json\encoder.py", line 404, in _iterencode_dict\n yield from chunks\n File "C:\Users\vinay\Anaconda3\envs\flask-ml\lib\json\encoder.py", line 325, in _iterencode_list\n yield from chunks\n File "C:\Users\vinay\Anaconda3\envs\flask-ml\lib\json\encoder.py", line 437, in _iterencode\n o = _default(o)\n File "C:\Users\vinay\Anaconda3\envs\flask-ml\lib\site-packages\flask\json.py", line 80, in default\n return _json.JSONEncoder.default(self, o)\n File "C:\Users\vinay\Anaconda3\envs\flask-ml\lib\json\encoder.py", line 180, in default\n o.class.name)\nTypeError: Object of type 'int64' is not JSON serializable\n"
}
The text was updated successfully, but these errors were encountered:
Good work Amir, I am trying to run your code but got the following error, I am using python3 and installed all the requirements.
Intial Analysis:
The error is because prediction list contains int64 type values, but jsonifying this list is throwing this error
return jsonify({'prediction': prediction})
Suggested fix
prediction_str = [str(i) for i in prediction] return jsonify({'prediction': prediction_str})
Converting the
int64
list to string array solled the error.Error:
{
"error": "Object of type 'int64' is not JSON serializable",
"trace": "Traceback (most recent call last):\n File "main.py", line 42, in predict\n return jsonify({'prediction': prediction})\n File "C:\Users\vinay\Anaconda3\envs\flask-ml\lib\site-packages\flask\json.py", line 263, in jsonify\n (dumps(data, indent=indent, separators=separators), '\n'),\n File "C:\Users\vinay\Anaconda3\envs\flask-ml\lib\site-packages\flask\json.py", line 123, in dumps\n rv = _json.dumps(obj, **kwargs)\n File "C:\Users\vinay\Anaconda3\envs\flask-ml\lib\json\init.py", line 238, in dumps\n **kw).encode(obj)\n File "C:\Users\vinay\Anaconda3\envs\flask-ml\lib\json\encoder.py", line 201, in encode\n chunks = list(chunks)\n File "C:\Users\vinay\Anaconda3\envs\flask-ml\lib\json\encoder.py", line 430, in _iterencode\n yield from _iterencode_dict(o, _current_indent_level)\n File "C:\Users\vinay\Anaconda3\envs\flask-ml\lib\json\encoder.py", line 404, in _iterencode_dict\n yield from chunks\n File "C:\Users\vinay\Anaconda3\envs\flask-ml\lib\json\encoder.py", line 325, in _iterencode_list\n yield from chunks\n File "C:\Users\vinay\Anaconda3\envs\flask-ml\lib\json\encoder.py", line 437, in _iterencode\n o = _default(o)\n File "C:\Users\vinay\Anaconda3\envs\flask-ml\lib\site-packages\flask\json.py", line 80, in default\n return _json.JSONEncoder.default(self, o)\n File "C:\Users\vinay\Anaconda3\envs\flask-ml\lib\json\encoder.py", line 180, in default\n o.class.name)\nTypeError: Object of type 'int64' is not JSON serializable\n"
}
The text was updated successfully, but these errors were encountered: