在Python中使用Swagger和Connexion获取utf-8而不是\ u转义序列

问题描述

我正在尝试使用Swagger使用Python和Connexion构建API。我想生成 UTF-8编码的JSON 输出,但是在响应中得到这样的 \ u 转义序列:

euro \u20ac

代替此:

euro €

我已经为端点指定了字符集,也许我在规范中缺少有关编组的其他Swagger设置:

produces:
- "application/json; charset=utf-8"

并且响应头正确返回了内容类型:

HTTP/1.0 200 OK
Content-Type: application/json; charset=utf-8

我还尝试将其添加生成的“ swagger_server/__main__.py”中,结果相同:

app.app.json_encoder = encoder.JSONEncoder
app.app.json_encoder.ensure_ascii = False
app.app.json_encoder.encoding="utf-8"

编辑:这是我的 requirements.txt 。 SwaggerEditor生成的版本在使用Python 3.6.9的Ubuntu 18.04上不起作用,它需要 connexion == 1.1.15 ,但失败,并出现 ImportError:无法导入名称“ FileStorage” 。有人提供正确的答案会很棒。现在,我只需要 Connexion 及其依赖项:

connexion == 2.4.0
python_dateutil == 2.6.0
setuptools >= 21.0.0

如何实现? 谢谢!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)