python - UnicodeEncodeError when running in mod_wsgi even after setting LANG and LC_ALL -
i unicodeencodeerror
error when printing unicode string app. runs via elastic beanstalk on aws (apache + mod_wsgi). found this useful, , when call locale.getdefaultlocale()
, locale.getpreferredencoding()
none
, ascii
.
i set lang
, lc_all
en_us.utf-8
(via wsgidaemonprocess directive , environment variables). when call locale.getdefaultlocale()
, locale.getpreferredencoding()
, ('en_us', 'utf-8')
, utf-8
. however, i'm still getting same unicodeencodeerror
.
sys.stdout
of type mod_wsgi.log
. couldn't find details on how check/set encoding of this.
i'm not sure how continue debugging @ point. how fix error?
this wsgi.conf default elastic beanstalk except added lang
, locale
wsgidaemonprocess directive.
loadmodule wsgi_module modules/mod_wsgi.so wsgipythonhome /opt/python/run/baselinenv wsgisocketprefix run/wsgi wsgirestrictembedded on <virtualhost *:80> alias /static/ /opt/python/current/app/static/ <directory /opt/python/current/app/static/> order allow,deny allow </directory> wsgiscriptalias / /opt/python/current/app/application.py <directory /opt/python/current/app/> require granted </directory> wsgidaemonprocess wsgi processes=1 threads=15 lang='en_us.utf-8' locale='en_us.utf-8' display-name=%{group} python-path=/opt/python/current/app:/opt/python/run/venv/lib/python2.7/site-packages user=wsgi group=wsgi home=/opt/python/current/app wsgiprocessgroup wsgi </virtualhost>
traceback:
error:discotech:exception on /venues [get] traceback (most recent call last): file "/opt/python/run/venv/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app response = self.full_dispatch_request() file "/opt/python/run/venv/lib/python2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request rv = self.handle_user_exception(e) file "/opt/python/run/venv/lib/python2.7/site-packages/flask_cors/extension.py", line 110, in wrapped_function return cors_after_request(app.make_response(f(*args, **kwargs))) file "/opt/python/run/venv/lib/python2.7/site-packages/flask/app.py", line 1381, in handle_user_exception reraise(exc_type, exc_value, tb) file "/opt/python/run/venv/lib/python2.7/site-packages/flask/app.py", line 1475, in full_dispatch_request rv = self.dispatch_request() file "/opt/python/run/venv/lib/python2.7/site-packages/flask/app.py", line 1461, in dispatch_request return self.view_functions[rule.endpoint](**req.view_args) file "/opt/python/current/app/discotech/api/venue.py", line 32, in get_venues print "test = %s", test unicodeencodeerror: 'ascii' codec can't encode character u'\\xe1' in position 1: ordinal not in range(128)
here code i'm using exercise it:
# -*- coding: utf-8 -*- ... @api_app.route('/venues') def get_venues(): test = u"ián" print "test =", test
Comments
Post a Comment