Giter VIP home page Giter VIP logo

Comments (7)

GrahamDumpleton avatar GrahamDumpleton commented on June 23, 2024 2

Solution is that also need to set environment variable:

PYTHONIOENCODING=UTF-8

This is as well as LANG and LC_ALL.

from s2i-python-container.

GrahamDumpleton avatar GrahamDumpleton commented on June 23, 2024

I have written a blog about this problem before:

from s2i-python-container.

GrahamDumpleton avatar GrahamDumpleton commented on June 23, 2024

Hmmm, Gunicorn seems to fail to do the right thing even when these environment variables are set.

-- GLOBAL --
('en_US', 'UTF-8')
UTF-8
------------
-- REQUEST --
('en_US', 'UTF-8')
UTF-8
------------
[2016-12-06 20:20:30,923] ERROR in app: Exception on / [GET]
Traceback (most recent call last):
  File "/opt/app-root/src/.local/lib/python2.7/site-packages/flask/app.py", line 1988, in wsgi_app
    response = self.full_dispatch_request()
  File "/opt/app-root/src/.local/lib/python2.7/site-packages/flask/app.py", line 1641, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/opt/app-root/src/.local/lib/python2.7/site-packages/flask/app.py", line 1544, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/opt/app-root/src/.local/lib/python2.7/site-packages/flask/app.py", line 1639, in full_dispatch_request
    rv = self.dispatch_request()
  File "/opt/app-root/src/.local/lib/python2.7/site-packages/flask/app.py", line 1625, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/opt/app-root/src/wsgi.py", line 13, in hello
    print(u'\u292e')
UnicodeEncodeError: 'ascii' codec can't encode character u'\u292e' in position 0: ordinal not in range(128)

Additionally setting LC_LANG doesn't help.

Spin up python on the command line and works okay where as didn't before environment variables set. When I have run Python 3.5 app.py with aiohttpd application before problem was solved by environment variables. So Gunicorn is doing something nasty with its fiddling with stdout or stderr or need to provide other options to gunicorn when run is executing it.

from s2i-python-container.

GrahamDumpleton avatar GrahamDumpleton commented on June 23, 2024

This problem is only occurring with gunicorn when it is run from the run script triggered on container start. If you get an interactive shell using oc rsh and in that run gunicorn against a wsgi.py file which prints out a problematic string on import it works fine. Similarly, if use oc debug and run run manually, works fine.

from s2i-python-container.

GrahamDumpleton avatar GrahamDumpleton commented on June 23, 2024

This goes beyond gunicorn and seems to be an issue in general with Python 2.7 in a container where when not associated with a tty/interactive shell, default encoding doesn't get applied to stdout and stderr.

from s2i-python-container.

pkubatrh avatar pkubatrh commented on June 23, 2024

Closed via #167

from s2i-python-container.

lily524 avatar lily524 commented on June 23, 2024

for supervisor + gunicorn, can be config as below.

# other program config

[program:gunicorn]
command = gunicorn wsgi  --bind 0.0.0.0:8000 --log-level error ...
environment = LANG=en_US.UTF-8,LC_ALL=en_US.UTF-8,PYTHONIOENCODING=UTF-8

#other program config

from s2i-python-container.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.