flask-lambda
flask-lambda copied to clipboard
TypeError: can assign only bytes, buffers, or iterables of ints in range(0, 256) when processing request.json using werkzeug 2.2.3 and higher
When calling request.json in DELETE or POST calls I receive the following stack trace error:
Traceback (most recent call last):
File "/var/lang/lib/python3.8/site-packages/flask/app.py", line 2190, in wsgi_app
response = self.full_dispatch_request()
File "/var/lang/lib/python3.8/site-packages/flask/app.py", line 1486, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/var/lang/lib/python3.8/site-packages/flask/app.py", line 1484, in full_dispatch_request
rv = self.dispatch_request()
File "/var/lang/lib/python3.8/site-packages/flask/app.py", line 1469, in dispatch_request
return self.ensure_sync(self.view_functions [rule.endpoint])(**view_args)
File "/var/task/app.py", line 105, in delete_queue_messages
data = request.json
File "/var/lang/lib/python3.8/site-packages/werkzeug/wrappers/request.py", line 561, in json
return self.get_json()
File "/var/lang/lib/python3.8/site-packages/werkzeug/wrappers/request.py", line 611, in get_json
data = self.get_data(cache=cache)
File "/var/Lang/lib/python3.8/site-packages/werkzeug/wrappers/request.py", line 423, in get_data
rv = self.stream.read()
File */var/lang/lib/python3.8/site-packages/werkzeug/wsgi.py',line 829, in readall
data = self.read(1024 * 64)
File * /var/lang/lib/python3.8/site-packages/werkzeug/wsgi.py*,Line 810, in readinto
b[:out_size] = data
TypeError: can assign only bytes, buffers, or iterables of ints in range(0, 256)
As title suggests I am using main branch of flask-lambda, flask 2.3.2 and werkzeug 2.3.6.
When app is run locally as a regular Flask app the request.json call does not result in TypeError.
This is the sample json payload that is being sent:
[{"messageId":"db784ca1-f1c1-4cdc-ae2c-957c92dffe59","receiptHandle":"AQEByDzxV3NYEa8iLDTI566XLWsOKPasuaj0oahWvaFa1a7hXJZVkKoxeoddIpQjouo5e4zyL5+/E57aagRdB9PMZ3Mcj5z9xSWpjtjvgW1QzEpcuhkn08kyC0jJ6EbQEPdStcejEncp9Mc+fnte8IwD9W5vjm5+2gczsH8nUOS7ZgEKdzXqmwAJH6Tv2xRymog02BtzYBlRO4j2ZQhrGJos4f1L0KnJnT3lLNnIGcQQnGyR2nZqjMo8lm99VK/eVC+ocK2MV0PVxWxP2pfL3YWd8ghjc8k0oNaalIdk4b3jIz8="}]
Facing the same issue here and I also saw: https://stackoverflow.com/questions/76632734/flask-not-able-to-get-requests-body-in-any-way
@ijunaidf Found the solution: https://stackoverflow.com/questions/68954080/serverless-flask-api-crashes-when-trying-to-consume-multipart-form-data.
Hopefully this solves others headaches. I also had to upgrade my api to python39 to had some urllib parsing.
Thank you!