【发布时间】:2019-07-12 09:23:50
【问题描述】:
尝试使用 forms 和 post 使用 Requests 包将图像发送到 Flask 服务器。但是烧瓶服务器无法解析密钥image。如何通过使用表单的请求以正确的格式发送图像。
Flask server.py
@app.route('/api/<model_name>/predict/', methods=['POST'])
def predict(model_name):
if "image" in request.files.keys():
return jsonify({"msg": "key found"})
print("image", request.files)
return str(), 200
请求 client.py
def get_predictions(path):
url = "http://localhost:9020/api/fasterrcnn/predict/"
payload = {"image": (path.name, open(path, "rb"), "image/jpeg")}
headers = {'content-type': "multipart/form-data"}
response = requests.post(
url, data=payload, headers=headers, stream=True)
pprint(response.text)
谁能告诉我可能的原因和解决方案?如果我遗漏了任何内容,过分或过分强调了某个特定点,请在 cmets 中告诉我。
【问题讨论】:
标签: python forms post flask python-requests