Bug #42651
closedmgr/dashboard: error when editing rbd image whose name contains non-ASCII chars.
0%
Description
Verified for this environment:
OS: CentOS 7
Python version: 2.7.5
After creating rbd image with name like "año" (non-ASCII chars: ñ),
if you try to edit image, you get an error:
2019-10-30T19:34:33.269+0000 7f8ca4be6700 0 mgr[dashboard] [30/Oct/2019:19:34:33] Traceback (most recent call last): File "/usr/lib/python2.7/site-packages/cherrypy/_cprequest.py", line 102, in run hook() File "/usr/lib/python2.7/site-packages/cherrypy/_cprequest.py", line 62, in __call__ return self.callback(**self.kwargs) File "/ceph/src/pybind/mgr/dashboard/tools.py", line 53, in request_begin req.method, user, req.path_info) File "/usr/lib64/python2.7/logging/__init__.py", line 1137, in debug self._log(DEBUG, msg, args, **kwargs) File "/usr/lib64/python2.7/logging/__init__.py", line 1268, in _log self.handle(record) File "/usr/lib64/python2.7/logging/__init__.py", line 1278, in handle self.callHandlers(record) File "/usr/lib64/python2.7/logging/__init__.py", line 1318, in callHandlers hdlr.handle(record) File "/usr/lib64/python2.7/logging/__init__.py", line 749, in handle self.emit(record) File "/ceph/src/pybind/mgr/mgr_module.py", line 65, in emit self._module._ceph_log(ceph_level, self.format(record)) File "/usr/lib64/python2.7/logging/__init__.py", line 724, in format return fmt.format(record) File "/usr/lib64/python2.7/logging/__init__.py", line 464, in format record.message = record.getMessage() File "/usr/lib64/python2.7/logging/__init__.py", line 328, in getMessage msg = msg % self.args UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 21: ordinal not in range(128)
It seems that this line is the origin:
https://github.com/ceph/ceph/blob/master/src/pybind/mgr/dashboard/tools.py#L52
logger.debug('[%s:%s] [%s] [%s] %s', req.remote.ip, req.remote.port, req.method, user, req.path_info)
Updated by Ricardo Dias over 4 years ago
The issue can be reproduced with the following example:
from __future__ import unicode_literals import logging logging.basicConfig() log = logging.getLogger() log.setLevel(logging.DEBUG) log.debug("%s", b"ñ")
And it can be fixed by changing the last line to:
log.debug("%s", b"ñ".decode('utf-8'))
This means that maybe we should add some `.decode('utf-8')` to the strings passed to that logger call.
AFAICT this issue only happens in python2, if octopus will only support python3 then we just need to fix the nautilus version.
Updated by Ernesto Puerta over 4 years ago
- Assignee deleted (
Kiefer Chang)
- Ensuring PYTHONIOENCODING is set utf-8: https://sonnguyen.ws/fix-utf-8-issue-python-logger/
- Checking if setting the encoding of the logging Handler fixes the issue: https://docs.python.org/2.7/library/logging.handlers.html#logging.FileHandler
Updated by Kiefer Chang over 4 years ago
AFAICT this issue only happens in python2, if octopus will only support python3 then we just need to fix the nautilus version.
Confirmed that this doesn't happen in python3.
Updated by Kiefer Chang over 4 years ago
(In python2)
With
diff --git a/src/pybind/mgr/dashboard/tools.py b/src/pybind/mgr/dashboard/tools.py index 7eb23e535b..af03000b2a 100644 --- a/src/pybind/mgr/dashboard/tools.py +++ b/src/pybind/mgr/dashboard/tools.py @@ -44,7 +44,7 @@ class RequestLoggingTool(cherrypy.Tool): user = JwtManager.get_username() # Log the request. logger.debug('[%s:%s] [%s] [%s] %s', req.remote.ip, req.remote.port, - req.method, user, req.path_info) + req.method, user, req.path_info.decode('utf-8')) # Audit the request. if Settings.AUDIT_API_ENABLED and req.method not in ['GET']: url = build_url(req.remote.ip, scheme=req.scheme,
I'm getting encoding error:
2019-11-12 09:25:32.402 7faeec78a700 0 mgr[dashboard] [12/Nov/2019:09:25:32] Traceback (most recent call last): File "/usr/lib/python2.7/site-packages/cherrypy/_cprequest.py", line 104, in run hook() File "/usr/lib/python2.7/site-packages/cherrypy/_cprequest.py", line 63, in __call__ return self.callback(**self.kwargs) File "/ceph/src/pybind/mgr/dashboard/tools.py", line 47, in request_begin req.method, user, req.path_info.decode('utf-8')) File "/usr/lib64/python2.7/logging/__init__.py", line 1155, in debug self._log(DEBUG, msg, args, **kwargs) File "/usr/lib64/python2.7/logging/__init__.py", line 1286, in _log self.handle(record) File "/usr/lib64/python2.7/logging/__init__.py", line 1296, in handle self.callHandlers(record) File "/usr/lib64/python2.7/logging/__init__.py", line 1336, in callHandlers hdlr.handle(record) File "/usr/lib64/python2.7/logging/__init__.py", line 759, in handle self.emit(record) File "/ceph/src/pybind/mgr/mgr_module.py", line 65, in emit self._module._ceph_log(ceph_level, self.format(record)) UnicodeEncodeError: 'ascii' codec can't encode character u'\xf1' in position 59: ordinal not in range(128)
Start mgr daemon with PYTHONIOENCODING=utf-8 doesn't help either.
But with
diff --git a/src/pybind/mgr/dashboard/tools.py b/src/pybind/mgr/dashboard/tools.py index 7eb23e535b..a5166e8a98 100644 --- a/src/pybind/mgr/dashboard/tools.py +++ b/src/pybind/mgr/dashboard/tools.py @@ -43,6 +43,8 @@ class RequestLoggingTool(cherrypy.Tool): req = cherrypy.request user = JwtManager.get_username() # Log the request. + if user is not None: + user = user.encode('utf-8') logger.debug('[%s:%s] [%s] [%s] %s', req.remote.ip, req.remote.port, req.method, user, req.path_info) # Audit the request.
The exception is gone and the message is logged (but año becomes a\xc3\xb1o). The only variable in `unicode` type in this line is user, others are in `str`
Updated by Nathan Cutler over 4 years ago
Kiefer Chang wrote:
AFAICT this issue only happens in python2, if octopus will only support python3 then we just need to fix the nautilus version.
Confirmed that this doesn't happen in python3.
Please add this info to the actual commit message, so it's available in the git history.
Updated by Lenz Grimmer almost 4 years ago
- Status changed from In Progress to Resolved
- Target version changed from v15.0.0 to v14.2.10
Updated by Ernesto Puerta about 3 years ago
- Project changed from mgr to Dashboard
- Category changed from 139 to Component - RBD