我的脚本有很奇怪的行为。如果我只是将参数传递给get_results,一切正常,但是当我尝试从JSON传递参数时(使用POST请求),我的脚本失败了。有什么问题? 谢谢!
def get_results(condition, arr):
if len(arr) != 0:
res_arr = [finding_condition(arr[x], condition) for x in range(len(arr))]
final_temp = list(map(lambda x: cond_freq(condition) * x, res_arr))
final = [final_temp[k] for k in range(len(final_temp))]
result = np.prod(np.array(final))
print(result)
else:
result = cond_freq(condition)
print(result)
return result
@app.route("/", methods=['POST'])
def foo():
if not request.json:
abort(400)
print(request.json)
condition = request.json.get("condition")
findings = request.json.get("findings")
v = get_results(condition,findings)
print(v)
return v
curl -X POST -H "Content-Type: application/json" -d "{ \"condition\": \"Fibroadenoma\",\"findings\": [\"Mass\"] }" http://localhost:8000/
回溯:
File "C:\Program Files\Anaconda3\lib\site-packages\werkzeug\test.py", line 871, in run_wsgi_app
app_rv = app(environ, start_response)
TypeError: 'numpy.float64' object is not callable