Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KeyError: 'image' #3

Closed
rsingh2083 opened this issue Dec 7, 2020 · 5 comments
Closed

KeyError: 'image' #3

rsingh2083 opened this issue Dec 7, 2020 · 5 comments

Comments

@rsingh2083
Copy link

While uploading the image from mobile im getting this error. I even tried using 4.9.0 version of okhttp but still the same error.

192.168.31.250 - - [07/Dec/2020 16:08:55] "POST / HTTP/1.1" 500 -
Traceback (most recent call last):
File "/home/ubuntu/.local/lib/python3.6/site-packages/flask/app.py", line 2464, in call
return self.wsgi_app(environ, start_response)
File "/home/ubuntu/.local/lib/python3.6/site-packages/flask/app.py", line 2450, in wsgi_app
response = self.handle_exception(e)
File "/home/ubuntu/.local/lib/python3.6/site-packages/flask/app.py", line 1867, in handle_exception
reraise(exc_type, exc_value, tb)
File "/home/ubuntu/.local/lib/python3.6/site-packages/flask/_compat.py", line 39, in reraise
raise value
File "/home/ubuntu/.local/lib/python3.6/site-packages/flask/app.py", line 2447, in wsgi_app
response = self.full_dispatch_request()
File "/home/ubuntu/.local/lib/python3.6/site-packages/flask/app.py", line 1952, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/home/ubuntu/.local/lib/python3.6/site-packages/flask/app.py", line 1821, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/home/ubuntu/.local/lib/python3.6/site-packages/flask/_compat.py", line 39, in reraise
raise value
File "/home/ubuntu/.local/lib/python3.6/site-packages/flask/app.py", line 1950, in full_dispatch_request
rv = self.dispatch_request()
File "/home/ubuntu/.local/lib/python3.6/site-packages/flask/app.py", line 1936, in dispatch_request
return self.view_functionsrule.endpoint
File "/home/ubuntu/Downloads/AndroidFlask-master/Part 2/FlaskServer/flask_server.py", line 11, in handle_request
imagefile = flask.request.files['image']
File "/home/ubuntu/.local/lib/python3.6/site-packages/werkzeug/datastructures.py", line 442, in getitem
raise exceptions.BadRequestKeyError(key)
werkzeug.exceptions.BadRequestKeyError: 400 Bad Request: The browser (or proxy) sent a request that this server could not understand.
KeyError: 'image'
File "/home/raghavz/.local/lib/python3.6/site-packages/werkzeug/datastructures.py", line 442, in getitem
raise exceptions.BadRequestKeyError(key)
werkzeug.exceptions.BadRequestKeyError: 400 Bad Request: The browser (or proxy) sent a request that this server could not understand.
KeyError: 'image'

@ahmedfgad
Copy link
Owner

Hi,

You are right.

A quick solution is to edit the next line from the flask_server.py script (https://github.com/ahmedfgad/AndroidFlask/blob/master/Part%202/FlaskServer/flask_server.py):

imagefile = flask.request.files['image']

The new line should use image0 rather than image as the key.

imagefile = flask.request.files['image0']

This will allow you to upload only a single image from the client to the server. I will update the project later to support multiplt image upload.

Please let me know if there still any issue.

@rsingh2083
Copy link
Author

rsingh2083 commented Dec 7, 2020

Thanks a lot buddy. Now im getting this error. I selected a different Image from my mobile. The images which you have provided for the digits are not getting selected for uplaod and I get the error - "Something went wrong"..Hence I tried with a random image, but then getting this error

File "/home/ubuntu/Downloads/AndroidFlask-master/Part 2/FlaskServer/flask_server.py", line 17, in handle_request
img = img.reshape(784)
ValueError: cannot reshape array of size 2332800 into shape (784,)

@ahmedfgad
Copy link
Owner

Note that the project expects a MNIST image of shape 28x28. I think you selected an image of different shape.

@rsingh2083
Copy link
Author

Thanks Ahmad I tried copying the mnist example images in screenshot directory only then I was able to upload them.
But now getting this different error :-)

File "/home/ubuntu/Downloads/AndroidFlask-master/Part 2/FlaskServer/flask_server.py", line 18, in handle_request
loaded_model = keras.models.load_model('model.h5')
File "/home/ubuntu/.local/lib/python3.6/site-packages/keras/models.py", line 269, in load_model
model_config = json.loads(model_config.decode('utf-8'))
AttributeError: 'str' object has no attribute 'decode'

@rsingh2083
Copy link
Author

Solved it by downgrading h5py to 2.10.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants