Biv*_*ali 3 python flask postman
我想通过 POSTMAN 中的 POST 方法传递图像,但我在 request.files['image'] 行中得到 None 类型响应
我尝试了很多不同的方法,但无法解决问题。
from flask import Flask,jsonify
from flask import request
import face_recognition
import json
app = Flask(__name__)
@app.route('/')
def index():
return ''
@app.route('/valid_faces', methods=['POST'])
def POST():
if request.method == 'POST':
# getting the images url from the request
print('....')
name1 = request.files['file'] if request.files.get('file') else None
print('....')
print (name1) # name2 = request.form.get('name2')
# map the url to the ones in the folder images
firstImage = name1
# loading the image inside a variable
firstImage = face_recognition.load_image_file(firstImage)
result=face_recognition.face_locations(firstImage)
if result:
# x={'valid_faces':True}
# return jsonify(x)
return "True"
else:
# x={'valid_faces':False}
# return jsonify(x)
return "False"
if __name__ == "__main__":
app.run(debug=True)
Run Code Online (Sandbox Code Playgroud)
小智 8
如果您希望将文件附加到邮递员调用,则需要将其添加到正文中。检查form-data并选择file而不是text. 您现在可以使用 Windows 文件资源管理器选择文件。
要获取给定的文件,请使用该request包。
file = request.files['file']
Run Code Online (Sandbox Code Playgroud)
索引必须与您在邮递员正文数据中指定的字符串相同。
| 归档时间: |
|
| 查看次数: |
6305 次 |
| 最近记录: |