uWSGI / Emperor: UnicodeEncodeError: 'ascii' codec can't encode character

瘦欲@ 提交于 2019-12-07 04:17:49

问题


i have big problem with encoding on uwsgi/emeror/nginx server. My app is developed to batch excel files processing.

I use latest version flask and flask-extensions and use flask-excel.

My app runs on Digital Ocean / Ubuntu server and my config files are:

/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/sites-enabled/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;
    }

}

and here is my problem: When start application with command:

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

and upload excel files works all great BUT

when start same aplication with totaly same config files (in /etc/init/uwsgi.conf) with emperor, application works fine, but when upload excel file to batch processing, i see only message: "502 Bad Gateway" and in my log is:

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

i was try install uwsgi with apt-get / pip3 install and scenario is same: when run app directly without emperor, works all fine; when run app with emperor (with same configuration), every upload excel file to my app ends with crash :/

Thanks for any answer


回答1:


add the following lines to your abissk_uwsgi.ini file to enforce uwsgi to use UTF-8.

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



回答2:


Add to uwsgi.ini:

env = LANG=en_US.UTF-8

Only this format helped for me




回答3:


for Russian language add this in uwsgi.ini

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



回答4:


None of the variables LANG, LC_ALL, LC_LANG helped me.

I fixed the bug only adding this to the uwsgi.ini:

env = PYTHONIOENCODING=UTF-8



来源:https://stackoverflow.com/questions/32452529/uwsgi-emperor-unicodeencodeerror-ascii-codec-cant-encode-character

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!