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

UnicodeDecodeError: 'gbk' codec can't decode byte 0xaf in position #249

Closed
fangaofeng opened this issue Jun 13, 2016 · 1 comment
Closed
Assignees

Comments

@fangaofeng
Copy link

Description

swagger-editer generator server python flask based connexion, when i run app.

Expected bahaviour

Traceback (most recent call last):
File "E:\eclipsephp\plugins\org.python.pydev_4.5.4.201601292234\pysrc\pydevd.py", line 1524, in
globals = debugger.run(setup['file'], None, None, is_module)
File "E:\eclipsephp\plugins\org.python.pydev_4.5.4.201601292234\pysrc\pydevd.py", line 931, in run
pydev_imports.execfile(file, globals, locals) # execute the script
File "E:\eclipsephp\plugins\org.python.pydev_4.5.4.201601292234\pysrc_pydev_imps_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "E:\pworkspace\testrest\examples\python-flask-server\app.py", line 6, in
app.add_api('swagger.yaml', arguments={'title': ''})
File "E:\pythonvenv\flaskvenv\lib\site-packages\connexion\app.py", line 146, in add_api
debug=self.debug)
File "E:\pythonvenv\flaskvenv\lib\site-packages\connexion\api.py", line 89, in init
swagger_template = swagger_yaml.read()
UnicodeDecodeError: 'gbk' codec can't decode byte 0xaf in position 266: illegal multibyte sequence

Actual behaviour

Steps to reproduce

orig:
with swagger_yaml_path.open() as swagger_yaml:
swagger_template = swagger_yaml.read()
change:
with swagger_yaml_path.open(encoding='utf-8') as swagger_yaml:
swagger_template = swagger_yaml.read()

and then is run success.

Additional info:

Output of the commands:

  • python --version3.5.1
  • pip show connexion | grep "^Version\:"
    connexion-1.0.97
    in windows10 64 run
@jmcs
Copy link
Contributor

jmcs commented Jun 13, 2016

By default, python tries to open files with your system's prefered encoding (as returned by locale.getpreferredencoding()) Hardcoding 'utf-8' breaking connexion for people that want to use other encodings. A solution would be to include an optional encoding argument to add_api

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

3 participants