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

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 #20

Open
cmarsh4473 opened this issue Jun 13, 2023 · 4 comments

Comments

@cmarsh4473
Copy link

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.

@cmarsh4473
Copy link
Author

This is the sample json payload that is being sent:

[{"messageId":"db784ca1-f1c1-4cdc-ae2c-957c92dffe59","receiptHandle":"AQEByDzxV3NYEa8iLDTI566XLWsOKPasuaj0oahWvaFa1a7hXJZVkKoxeoddIpQjouo5e4zyL5+/E57aagRdB9PMZ3Mcj5z9xSWpjtjvgW1QzEpcuhkn08kyC0jJ6EbQEPdStcejEncp9Mc+fnte8IwD9W5vjm5+2gczsH8nUOS7ZgEKdzXqmwAJH6Tv2xRymog02BtzYBlRO4j2ZQhrGJos4f1L0KnJnT3lLNnIGcQQnGyR2nZqjMo8lm99VK/eVC+ocK2MV0PVxWxP2pfL3YWd8ghjc8k0oNaalIdk4b3jIz8="}]

@ijunaidf
Copy link

@cmarsh4473
Copy link
Author

@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.

@ijunaidf
Copy link

Thank you!

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