uWSGI / Emperor:UnicodeEncodeError:'ascii'编解码器不能编码字符

我在uwsgi / emeror / nginx服务器上编码时遇到了很大的问题。 我的应用程序开发批处理excel文件处理。

我使用最新版本的烧瓶和烧瓶扩展名,并使用flask-excel。

我的应用程序在Digital Ocean / Ubuntu服务器上运行,我的configuration文件是:

/etc/init/uwsgi.conf

description "uWSGI" start on runlevel [2345] stop on runlevel [06] respawn env UWSGI=/home/lukas/www/abissk/venv/bin/uwsgi env LOGTO=/home/lukas/logs/abissk/emperor.log exec $UWSGI --master --emperor /etc/uwsgi/vassals --die-on-term --uid www-data --gid www-data --logto $LOGTO 

/etc/uwsgi/vassals/abissk_uwsgi.ini

 [uwsgi] plugins = python #pcre = True #application's base folder base = /home/lukas/www/abissk/ #enable-threads = true #python module to import app = wsgi module = %(app) home = %(base)venv pythonpath = %(base) #socket file's location socket = /home/lukas/www/abissk/%n.sock #permissions for the socket file chmod-socket = 644 #the variable that holds a flask application inside the module imported at line #6 callable = app #location of log files logto = /home/lukas/logs/abissk/%n.log 

/home/lukas/www/abissk/wsgi.py

 # -*- coding: utf-8 *-* from app.app import create_app from app.settings import ProdConfig app = create_app(config_object=ProdConfig) 

在/ etc / nginx的/启用的站点 – / abissk_nginx

 server { listen 80; server_name benela.abis.sk; charset utf-8; client_max_body_size 75M; location / { try_files $uri @yourapplication; } location @yourapplication { include uwsgi_params; uwsgi_pass unix:/home/lukas/www/abissk/abissk_uwsgi.sock; } } 

这里是我的问题:当用命令启动应用程序时:

  ~/www/abissk/venv/bin/uwsgi --ini /etc/uwsgi/vassals/abissk_uwsgi.ini 

并上传Excel文件工作都很好,但是

当用皇帝启动与同样的configuration文件(在/etc/init/uwsgi.conf)相同的应用程序时,应用程序工作正常,但是当上传excel文件到批处理时,我只看到消息:“502 Bad Gateway”,在我的日志是:

  UnicodeEncodeError: 'ascii' codec can't encode character '\xfd' in position 31: ordinal not in range(128) 

我试着用apt-get / pip3安装uwsgi安装和场景是一样的:当没有皇帝直接运行应用时,工作都很好; 当与皇帝(具有相同的configuration)运行的应用程序,每个上传Excel文件到我的应用程序以崩溃结束:/

感谢您的任何答案

将以下行添加到abissk_uwsgi.ini文件中,以强制uwsgi使用UTF-8。

 env LANG="en_US.utf8" env LC_ALL="en_US.UTF-8" env LC_LANG="en_US.UTF-8" 

添加到uwsgi.ini

 env = LANG=en_US.UTF-8 

只有这种格式对我有帮助

LANGLC_ALLLC_LANG帮助我。

我修正了这个bug,只是把它添加到了uwsgi.ini中:

env = PYTHONIOENCODING=UTF-8

对于俄语在uwsgi.ini中添加这个

 env = LANG=ru_RU.utf8 env = LC_ALL=ru_RU.UTF-8 env = LC_LANG=ru_RU.UTF-8