From 1a402be175e20d27cb3c6d9b0c23dd4aaedc5c85 Mon Sep 17 00:00:00 2001 From: Markus Heiser Date: Mon, 26 Apr 2021 11:36:35 +0200 Subject: [PATCH] [fix] debug log: UnicodeEncodeError: 'ascii' codec can't encode The issue exists only in the debug log:: --- Logging error --- Traceback (most recent call last): File "/usr/lib/python3.9/logging/__init__.py", line 1086, in emit stream.write(msg + self.terminator) UnicodeEncodeError: 'ascii' codec can't encode characters in position 79-89: ordinal not in range(128) Call stack: File "/usr/local/searx/searx-pyenv/lib/python3.9/site-packages/flask/app.py", line 2464, in __call__ return self.wsgi_app(environ, start_response) File "/usr/local/searx/searx-src/searx/webapp.py", line 1316, in __call__ return self.app(environ, start_response) File "/usr/local/searx/searx-pyenv/lib/python3.9/site-packages/werkzeug/middleware/proxy_fix.py", line 169, in __call__ return self.app(environ, start_response) File "/usr/local/searx/searx-pyenv/lib/python3.9/site-packages/flask/app.py", line 2447, in wsgi_app response = self.full_dispatch_request() File "/usr/local/searx/searx-pyenv/lib/python3.9/site-packages/flask/app.py", line 1950, in full_dispatch_request rv = self.dispatch_request() File "/usr/local/searx/searx-pyenv/lib/python3.9/site-packages/flask/app.py", line 1936, in dispatch_request return self.view_functions[rule.endpoint](**req.view_args) File "/usr/local/searx/searx-src/searx/webapp.py", line 766, in search number_of_results=format_decimal(number_of_results), File "/usr/local/searx/searx-pyenv/lib/python3.9/site-packages/flask_babel/__init__.py", line 458, in format_decimal locale = get_locale() File "/usr/local/searx/searx-pyenv/lib/python3.9/site-packages/flask_babel/__init__.py", line 226, in get_locale rv = babel.locale_selector_func() File "/usr/local/searx/searx-src/searx/webapp.py", line 249, in get_locale logger.debug("%s uses locale `%s` from %s", request.url, locale, locale_source) Unable to print the message and arguments - possible formatting error. Use the traceback above to help find the error. Signed-off-by: Markus Heiser --- searx/webapp.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/searx/webapp.py b/searx/webapp.py index 69ec915a7..70d2d662b 100755 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -54,6 +54,7 @@ from datetime import datetime, timedelta from timeit import default_timer from html import escape from io import StringIO +import urllib from urllib.parse import urlencode, urlparse from pygments import highlight @@ -246,7 +247,10 @@ def get_locale(): request.form['use-translation'] = 'oc' locale = 'fr_FR' - logger.debug("%s uses locale `%s` from %s", request.url, locale, locale_source) + logger.debug( + "%s uses locale `%s` from %s", urllib.parse.quote(request.url), locale, locale_source + ) + return locale