flask-restful出现字符串编码错误

  • 2016-12-14
  • 3,702

flask-restful插件编写api时,会用到reqparse.RequestParser模块,但是此模块在处理中文时会出现编码错误

比如代码如下:

当请求中出现中文时会返回错误
{ "message": { "fromAttr": "'ascii' codec can't encode characters in position 0-2: ordinal not in range(128)" } }

这是因为在add_argument模块中str表示接受unicode字符,并不是str字符,所以在使用str前,我会互换str和unicode

链接:https://www.ioiogoo.cn/2016/12/14/flask-restful出现字符串编码错误/
本站所有文章除特殊说明外均为原创,转载请注明出处!