uWSGI/Emperor:UnicodeEncodeError:'ascii'编解码器无法编码字符 [英] uWSGI / Emperor: UnicodeEncodeError: 'ascii' codec can't encode character

查看:79
本文介绍了uWSGI/Emperor:UnicodeEncodeError:'ascii'编解码器无法编码字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在uwsgi/emeror/nginx服务器上编码存在很大问题. 我的应用程序是为批量处理excel文件而开发的.

i have big problem with encoding on uwsgi/emeror/nginx server. My app is developed to batch excel files processing.

我使用最新版本的flask和flask-extensions,并使用flask-excel.

I use latest version flask and flask-extensions and use flask-excel.

我的应用程序在Digital Ocean/Ubuntu服务器上运行,我的配置文件为:

My app runs on Digital Ocean / Ubuntu server and my config files are:

/etc/init/uwsgi.conf

/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

/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

/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

/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

上传excel文件非常有用

and upload excel files works all great BUT

当与带有皇帝的完全相同的配置文件(在/etc/init/uwsgi.conf中)开始相同的复制时,应用程序运行良好,但是当将excel文件上传到批处理时,我仅看到消息:"502 Bad Gateway",并且在我的日志中是:

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)

我曾尝试使用apt-get/pip3 install安装uwsgi,并且场景是相同的:当直接运行应用程序而没有皇帝时,一切正常;当使用Emperor(具有相同的配置)运行应用程序时,每个上载到我的应用程序的excel文件都以崩溃结尾:/

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 :/

感谢您的回答

推荐答案

将以下几行添加到abissk_uwsgi.ini文件中,以强制uwsgi使用UTF-8.

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

这篇关于uWSGI/Emperor:UnicodeEncodeError:'ascii'编解码器无法编码字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆