5

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

4 Answers 4

7

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 
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks. I needed to make it env = LANG=en_US.utf8 as suggested
For anyone using Docker, try C.UTF-8 instead. Or you might need to install the locales first. Refer to stackoverflow.com/a/41648500/336694
Added env = PYTHONIOENCODING=UTF-8 as well
5

Add to uwsgi.ini:

env = LANG=en_US.UTF-8 

Only this format helped for me

1 Comment

This can be set to any of the UTF-8 encodings and is probably best set to whatever the system default locale is set to. For example I used env = LANG=en_AU.UTF8 as this is what my system default locale is set to in /etc/default/locale
1

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 

Comments

1

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.