question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

UnicodeDecodeError in /apispec_1.json

See original GitHub issue

An 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:closed
  • Created 6 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
AngelLiangcommented, May 10, 2018

Yeah! Thanks MedyG. I can use this successfully:

import yaml
from flasgger.utils import swag_from

@swag_from(yaml.load(open("path/to/file.yml"), encoding="utf-8"))
def view_function():
    pass
1reaction
MedyGcommented, Jan 24, 2018

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

try:
   with open(swag_path) as yaml_file:
       return yaml_file.read()

I add attr encoding='utf-8' into open() and I can swag the file encoded in utf-8 now. I don’t think this is a nice way to solve this problem, but I hope that flasgger can support encoding attr.

Best wishes!

Using PyYaml to read the yml as dict obj, then put this dict into swag_from, can also solve my problem.

Read more comments on GitHub >

github_iconTop Results From Across the Web

UnicodeDecodeError in /apispec_1.json · Issue #156 - GitHub
An error ocurred in docs when I put characters with "ç", "ã", etc. UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 844: ......
Read more >
open('*.json') gives "UnicodeDecodeError" - Stack Overflow
I'm trying to import a .json file as a dictionary using the following code: import json with open('StreamingHistory0.json') as json_file: ...
Read more >
How to fix UnicodeDecodeError on the OpenAi data ...
I was trying to prepare my dataset in a json format using the OpenAi data preparation tool (openai tools fine_tunes.prepare_data -f ...
Read more >
Issue 43340: json.load() can raise UnicodeDecodeError, but ...
loads() says: « If the data being deserialized is not a valid JSON document, a JSONDecodeError will be raised. » But this is...
Read more >
Python UnicodeDecodeError utf-8 codec can t decode byte ...
Unable to import this file it shows an error. My code was: import pandas as pd a = pd.read_csv("filename.csv")
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found