nginx – uWSGI / Emperor:UnicodeEncodeError:’ascii’编解码器无法编码字符

前端之家收集整理的这篇文章主要介绍了nginx – uWSGI / Emperor:UnicodeEncodeError:’ascii’编解码器无法编码字符前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

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

我使用最新版本的烧瓶和烧瓶扩展,并使用flask-excel.

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

/etc/init/uwsgi.conf

  1. description "uWSGI"
  2. start on runlevel [2345]
  3. stop on runlevel [06]
  4. respawn
  5. env UWSGI=/home/lukas/www/abissk/venv/bin/uwsgi
  6. env LOGTO=/home/lukas/logs/abissk/emperor.log
  7. exec $UWSGI --master --emperor /etc/uwsgi/vassals --die-on-term --uid www-data --gid www-data --logto $LOGTO

/etc/uwsgi/vassals/abissk_uwsgi.ini

  1. [uwsgi]
  2. plugins = python
  3. #pcre = True
  4. #application's base folder
  5. base = /home/lukas/www/abissk/
  6. #enable-threads = true
  7. #python module to import
  8. app = wsgi
  9. module = %(app)
  10. home = %(base)venv
  11. pythonpath = %(base)
  12. #socket file's location
  13. socket = /home/lukas/www/abissk/%n.sock
  14. #permissions for the socket file
  15. chmod-socket = 644
  16. #the variable that holds a flask application inside the module imported at line #6
  17. callable = app
  18. #location of log files
  19. logto = /home/lukas/logs/abissk/%n.log

/home/lukas/www/abissk/wsgi.py

  1. # -*- coding: utf-8 *-*
  2. from app.app import create_app
  3. from app.settings import ProdConfig
  4. app = create_app(config_object=ProdConfig)

在/ etc / Nginx的/启用的站点 – / abissk_Nginx

  1. server {
  2. listen 80;
  3. server_name benela.abis.sk;
  4. charset utf-8;
  5. client_max_body_size 75M;
  6. location / { try_files $uri @yourapplication; }
  7. location @yourapplication {
  8. include uwsgi_params;
  9. uwsgi_pass unix:/home/lukas/www/abissk/abissk_uwsgi.sock;
  10. }
  11. }

这是我的问题:
使用命令启动应用程序时:

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

上传excel文件工作得很好但是

当使用emperor与完全相同的配置文件(在/etc/init/uwsgi.conf中)启动相同的应用程序时,应用程序工作正常,但是当上传excel文件到批处理时,我只看到消息:“502 Bad Gateway”并在我的日志中是:

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

我尝试使用apt-get / pip3安装安装uwsgi并且场景相同:当没有皇帝直接运行应用程序时,工作正常;当使用emperor运行应用程序(具有相同配置)时,每个上传excel文件到我的应用程序以崩溃结束:/

谢谢你的回答

最佳答案
将以下行添加到您的abissk_uwsgi.ini文件中以强制uwsgi使用UTF-8.

  1. env LANG=en_US.utf8
  2. env LC_ALL=en_US.UTF-8
  3. env LC_LANG=en_US.UTF-8

猜你在找的Nginx相关文章