A solution to the coding problem in the detailed Uwsgi

Source: Internet
Author: User
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:

    • Ubuntu 16.04.1 LTS

    • Python 3.5.2

    • Uwsgi 2.0.14 (in Python3 PIP)

    • Supervisor 3.3.1 (in Python2 PIP)

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 "

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.