Recently in the application of flask written by SUPERVISOR+UWSGI deployed to the official server on the error, by finding the relevant data finally solved, so want to share out to everyone, the following article mainly introduces the solution to the UWSGI coding problems related information, You need a friend to refer to below.
Discover problems
There was a problem with the recent work, when the application that wrote Flask was deployed to the official server via SUPERVISOR+UWSGI, an error occurred:
Unable to print the message and arguments–possible formatting error.
Or
Unicodeencodeerror: ' ASCII ' codec can ' t encode characters in position 24-25:ordinal not in range (128)
Interestingly, there is no such error when running directly in the Python environment. It is also normal to run this way using Uwsgi Uwsgi.ini.
Because of the lack of support for Unicode, this error often occurs in Python2, but all of my programs are written in Python3 and should not be seen again. Moreover, all Python files are encoded in the first line:
#-*-Coding:utf-8-*-
My environment is as follows:
The contents of the Uwsgi.ini configuration file are as follows:
[Uwsgi]master = Truewsgi-file = manage.pycallable = appprocesses = 2threads = 2max-requests = 6000chmod-socket = 664uid = Appgid = Appbuffer-size = 32768venv = {project_dir}/venv; HTTP = 127.0.0.1:5001logto = {Project_dir}/logs/uwsgi.log
Because there is no such error in using Python and UWSGI directly, you can determine that the environment encoding setting is the cause of the problem.
The code for viewing the server is as follows:
% localelang=clanguage=c:lc_ctype= "en_US. UTF-8 "lc_numeric=" en_US. UTF-8 "Lc_time=" en_US. UTF-8 "Lc_collate=" en_US. UTF-8 "lc_monetary=" en_US. UTF-8 "lc_messages=" en_US. UTF-8 "Lc_paper=" en_US. UTF-8 "Lc_name=" en_US. UTF-8 "lc_address=" en_US. UTF-8 "Lc_telephone=" en_US. UTF-8 "Lc_measurement=" en_US. UTF-8 "lc_identification=" en_US. UTF-8 "Lc_all=en_us. UTF-8
The LANG and LANGUAGE environment variables were found to be not set.
You can set the values of these two environment variables in Uwsgi.ini. After testing, it is found that the actual effect is LANGUAGE.
Env lang= "en_US. UTF-8 "env language=" en_US. UTF-8 "