UWSGI / Emperor: UnicodeEncodeError: codec 'ascii' cannot encode character

I have a big problem with the encoding on the uwsgi / emeror / nginx server. My application is designed for batch processing excel files.

I use the latest flask and flask version and use the excel bottle.

My application runs on a Digital Ocean / Ubuntu server, and my configuration 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 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 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 with support / 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 starting the application with the command:

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

and excel file loading works fine, BUT

when I run the same application with total configuration files (in / etc / init / uwsgi.conf) with the emperor, the application works fine, but when I load the excel file into batch processing, I see only the message: "502 Bad Gateway" and in my log:

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

I tried to install uwsgi with apt-get / pip3 installed, and the scenario is the same: when starting the application directly without an emperor, everything works fine; when I start the application with the emperor (with the same configuration), every excel file loaded into my application crashes: /

Thanks for any answer

+5
source share
4 answers

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

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

Add to uwsgi.ini :

 env = LANG=en_US.UTF-8 

Only this format helped me

+4
source

None of the LANG , LC_ALL , LC_LANG helped me.

I fixed the error by adding it only to uwsgi.ini:

env = PYTHONIOENCODING=UTF-8

+1
source

for russian language add this to uwsgi.ini

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

All Articles