【发布时间】:2019-08-27 02:28:31
【问题描述】:
我想重新创建一个从 Flask 服务器发送的 .png 文件。 如果我在浏览器中获取文件,我可以查看它。 如果我从 python 请求中获取它,我会在保存文件时遇到问题,并且我永远无法查看它,因为格式似乎被破坏了。
客户:
req = requests.get(URL + "/image/file.png")
with open("recv.png", "wb") as f:
print(req.text)
f.write(req.text.encode())
服务器:
@app.route("/image/<string:path>")
def get(path):
return send_from_directory("images", path, mimetype="image/png", as_attachment=True)
【问题讨论】:
标签: python image rest download binary