我在烧瓶中有一个项目来获取参数并且它可以工作,如果我通过邮递员打电话。但是如果我用 java 代码来做,它会返回错误 400。
烧瓶:
@app.route('/predict', methods=["POST"])
def predict():
print("\nPredict......")
print(request.form)
print(request.form['textToPredict'])
print("\nPredict......2")
print(request.form.get("textToPredict"))
#print("Text...."+request.form['textToPredict'].toString())
# new text to predict
text_to_predict = [request.form['textToPredict'].lower()] #[request.form.get('textToPredict')] # ["asmatica desde infancia ex fumante 15 am dopc em uso de o2 ha 1 ano em uso de alenia 400 /12 e formoterol 12 2 x dia mvdiminuido sra brn f 2 t s/s cta rx pfp"] # este deve retornar CID Z00
#print("Text....:"+str(text_to_predict))
# count_vect gera as posições dos vetores de cada palavra do texto.
new = count_vect.transform(text_to_predict)
# carrega o modelo treinado
loaded_model = cPickle.load(open(fname, 'rb'))
# faz a predição do novo texto de entrada
result = loaded_model.predict(new)
print(result)
# accuracy_score(y_test, result)
json_dict = request.get_json()
text = ''.join(result)
textPredicted = text
data = {'textPredicted': textPredicted}
return jsonify(data), 200
java的输出(打印烧瓶代码):
Predict......
ImmutableMultiDict([('{"textToPredict":"coriza"}', '')])
127.0.0.1 - - [22/Oct/2018 16:07:34] "POST /predict HTTP/1.1" 400 -
邮递员的输出(打印 FLASK 代码):
Predict......
ImmutableMultiDict([('textToPredict', 'coriza, dificuldade em respirar, febre, dor no corpo')])
coriza, dificuldade em respirar, febre, dor no corpo
Predict......2
coriza, dificuldade em respirar, febre, dor no corpo
['J06 ']
127.0.0.1 - - [22/Oct/2018 16:20:00] "POST /predict HTTP/1.1" 200 -
所以,看起来我的错误是在发送帖子时,它是由 java 代码组成的。
我不明白错误的原因。在我看来,参数在到达烧瓶时是不正确的,根据它提供的输出。
我需要一些帮助来解决这个问题。谢谢你。
精慕HU
相关分类