UnicodeDecodeError in /apispec_1.json
See original GitHub issueAn error ocurred in docs when I put characters with “ç”, “ã”, etc.
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 844: ordinal not in range(128) File "flask/app.py", line 1982, in wsgi_app response = self.full_dispatch_request() File "flask/app.py", line 1614, in full_dispatch_request rv = self.handle_user_exception(e) File "flask_restful/__init__.py", line 271, in error_router return original_handler(e) File "flask_cors/extension.py", line 161, in wrapped_function return cors_after_request(app.make_response(f(*args, **kwargs))) File "flask/app.py", line 1517, in handle_user_exception reraise(exc_type, exc_value, tb) File "flask/_compat.py", line 33, in reraise raise value File "flask/app.py", line 1612, in full_dispatch_request rv = self.dispatch_request() File "flask/app.py", line 1598, in dispatch_request return self.view_functions[rule.endpoint](**req.view_args) File "flask/views.py", line 84, in view return self.dispatch_request(*args, **kwargs) File "flask/views.py", line 149, in dispatch_request return meth(*args, **kwargs) File "flasgger/base.py", line 229, in get endpoint=rule.endpoint, verb=verb File "flasgger/utils.py", line 318, in parse_docstring full_doc = load_from_file(swag_path, swag_type) File "flasgger/utils.py", line 295, in load_from_file return yaml_file.read() File "encodings/ascii.py", line 26, in decode return codecs.ascii_decode(input, self.errors)[0]
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (1 by maintainers)
Yeah! Thanks MedyG. I can use this successfully:
Similiar problem. I have a ‘utf-8’ encoding yml file where some chars are not pure english, when I use @swag_from(‘utils.yml’), I got the same error. So I review the code and find the code line 436 in
flasgger/utils.py
I add attr
encoding='utf-8'
into open() and I can swag the file encoded inutf-8
now. I don’t think this is a nice way to solve this problem, but I hope that flasgger can supportencoding
attr.Best wishes!
Using
PyYaml
to read theyml
asdict
obj, then put this dict into swag_from, can also solve my problem.