Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

nginx

flask

uwsgi

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

like image 391
lukassliacky Avatar asked Sep 08 '15 08:09

lukassliacky


2 Answers

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
like image 172
Jiloc Avatar answered Sep 27 '22 19:09

Jiloc


Add to uwsgi.ini:

env = LANG=en_US.UTF-8

Only this format helped for me

like image 32
Ivan Borshchov Avatar answered Sep 27 '22 20:09

Ivan Borshchov