I have a Flask application that it supposed to receive two images and output a , but when I run the app I get these errors, the code is working perfectly without Flask
Errors:
[ WARN:[email protected]] global /io/opencv/modules/imgcodecs/src/loadsave.cpp (239) findDecoder imread_('/home/criuser/Téléchargements/20210728_122019.jpg'): can't open/read file: check file path/integrity
[2022-02-15 22:17:15,439] ERROR in app: Exception on / [GET]
Traceback (most recent call last):
File "/home/criuser/PycharmProjects/FINAL_AI/venv/lib/python3.8/site-packages/flask/app.py", line 2073, in wsgi_app
response = self.full_dispatch_request()
File "/home/criuser/PycharmProjects/FINAL_AI/venv/lib/python3.8/site-packages/flask/app.py", line 1518, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/home/criuser/PycharmProjects/FINAL_AI/venv/lib/python3.8/site-packages/flask/app.py", line 1516, in full_dispatch_request
rv = self.dispatch_request()
File "/home/criuser/PycharmProjects/FINAL_AI/venv/lib/python3.8/site-packages/flask/app.py", line 1502, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
File "/home/criuser/PycharmProjects/FINAL_AI/venv/final.py", line 19, in API
result = change_bg.change_bg_img(f_image_path=original,
File "/home/criuser/PycharmProjects/FINAL_AI/venv/lib/python3.8/site-packages/pixellib/tune_bg/__init__.py", line 236, in change_bg_img
seg_image = self.segmentAsPascalvoc(f_image_path)
File "/home/criuser/PycharmProjects/FINAL_AI/venv/lib/python3.8/site-packages/pixellib/tune_bg/__init__.py", line 53, in segmentAsPascalvoc
h, w, n = image.shape
AttributeError: 'NoneType' object has no attribute 'shape'
127.0.0.1 - - [15/Feb/2022 22:17:15] "GET /?original=/home/criuser/Téléchargements/20210728_122019.jpg&background=/home/criuser/Téléchargements/Tableau_Dashboard.jpg HTTP/1.1" 500 -
Code:
curl "http://127.0.0.1:5000?original=/home/criuser/Téléchargements/20210728_122019.jpg&background=/home/criuser/Téléchargements/Tableau_Dashboard.jpg"
@app.route('/',methods=['GET'])
def API():
if request.method == 'GET':
original = request.args.get('original')
background = request.args.get('background')
change_bg = alter_bg(model_type="pb")
change_bg.load_pascalvoc_model("/home/criuser/Téléchargements/xception_pascalvoc.pb")
result = change_bg.change_bg_img(f_image_path=original,
b_image_path=background,
output_image_name="/home/criuser/Téléchargements/new.jpg")
img_base64 = base64.b64encode(result.read())
return jsonify(img_base64.decode())
None
instead image. First you could useprint()
to check what you get in variables. And next you could useif/else
to skip code when you getNone
inoriginal
orbackground
. BTW: you don't have to checkrequest.method == 'GET':
because you havemethods=['GET']
. But checkingrequest.method == 'GET':
doesn't check if you have?original=... &background=...
in url. – furas"status": "ok"
when you send image, or"status": "error"
when it couldn't create image. – furasrequest.args
. Maybe problem makes native charsé
because it showsTéléchargements
instead ofTéléchargements
– furascurl
which doesn't converté
. If I test your URL using web browser then it gets correctlyTéléchargements
. Maybecurl
uses different encoding to send native chars. – furas'é'.encode('latin1').decode()
I geté
- and it can meanscurl
sends URL aslatin1
butflask
expectsutf-8
. Web browser and commandwget
don't have this problem. – furas