I am trying create an API using Django and testing it using POSTMAN.
While trying to test the API using the below code i am getting error
@api_view(['POST','GET'])
def predict_plant_disease(request):
try:
if request.body:
request_data = request.data["plant_image"]
image_data = request_data.split(';base64,')
image_array,err_msg =image_converter.convert_image(request_data)
if err_msg == None :
model_file = f"{BASE_DIR}/ml_files/cnn_model.pkl"
saved_classifier_model = pickle.load(open(model_file,'rb'))
prediction = saved_classifier_model.predict(image_array)
label_binarizer = pickle.load(open(f"{BASE_DIR}/ml_files/label_transform.pkl",'rb'))
return_data = {
"error" : "0",
"data" : f"{label_binarizer.inverse_transform(prediction)[0]}"
}
else :
return_data = {
"error" : "4",
"message" : f"Error : {err_msg}"
}
else :
return_data = {
"error" : "1",
"message" : "Request Body is empty",
}
except Exception as e:
return_data = {
"error" : "3",
"message" : f"Error : {str(e)}",
}
return HttpResponse(json.dumps(return_data), content_type='application/json; charset=utf-8')
I am getting the error as 'InMemoryUploadedFile' object has no attribute 'split'" at second line in the outer if loop. Help me to solve this error.
Screen Shot showing the error while requesting for the result from POSTMAN API.