Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logging breaks with clients having IPv6 addresses with a scope component #2952

Open
not-a-kiwi opened this issue Sep 25, 2024 · 0 comments · May be fixed by #2953
Open

Logging breaks with clients having IPv6 addresses with a scope component #2952

not-a-kiwi opened this issue Sep 25, 2024 · 0 comments · May be fixed by #2953

Comments

@not-a-kiwi
Copy link

In some conditions (at least seen with traefik and MacOS) the client address contains a scope, (see https://www.rfc-editor.org/rfc/rfc4007#section-11.2 )
This breaks logging as the address component will have a % symbol, which is misparsed by the logging code

Here is an example traceback:

--- Logging error ---
Traceback (most recent call last):
  File "/usr/lib/python3.10/logging/__init__.py", line 1100, in emit
    msg = self.format(record)
  File "/usr/lib/python3.10/logging/__init__.py", line 943, in format
    return fmt.format(record)
  File "/usr/lib/python3.10/logging/__init__.py", line 678, in format
    record.message = record.getMessage()
  File "/usr/lib/python3.10/logging/__init__.py", line 368, in getMessage
    msg = msg % self.args
TypeError: must be real number, not str
Call stack:
  File "/usr/lib/python3.10/threading.py", line 973, in _bootstrap
    self._bootstrap_inner()
  File "/usr/lib/python3.10/threading.py", line 1016, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.10/threading.py", line 953, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/lib/python3.10/socketserver.py", line 683, in process_request_thread
    self.finish_request(request, client_address)
  File "/usr/lib/python3.10/socketserver.py", line 360, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/usr/lib/python3.10/socketserver.py", line 747, in __init__
    self.handle()
  File "/usr/local/lib/python3.10/dist-packages/werkzeug/serving.py", line 391, in handle
    super().handle()
  File "/usr/lib/python3.10/http/server.py", line 433, in handle
    self.handle_one_request()
  File "/usr/lib/python3.10/http/server.py", line 421, in handle_one_request
    method()
  File "/usr/local/lib/python3.10/dist-packages/werkzeug/serving.py", line 363, in run_wsgi
    execute(self.server.app)
  File "/usr/local/lib/python3.10/dist-packages/werkzeug/serving.py", line 327, in execute
    write(data)
  File "/usr/local/lib/python3.10/dist-packages/werkzeug/serving.py", line 264, in write
    self.send_response(code, msg)
  File "/usr/lib/python3.10/http/server.py", line 498, in send_response
    self.log_request(code)
  File "/usr/local/lib/python3.10/dist-packages/werkzeug/serving.py", line 460, in log_request
    self.log("info", '"%s" %s %s', msg, code, size)
  File "/usr/local/lib/python3.10/dist-packages/werkzeug/serving.py", line 469, in log
    _log(
  File "/usr/local/lib/python3.10/dist-packages/werkzeug/_internal.py", line 97, in _log
    getattr(_logger, type)(message.rstrip(), *args, **kwargs)
Message: 'fe80::xxxx:xxxx:xxxx:xxxx%end0 - - [15/Jul/2024 14:41:06] "%s" %s %s'

Note the last line which shows the client address being the source of the problem.

The error is not fatal but makes logging very noisy as the traceback is printed instead of a log message.

Environment:

  • Python version: 3.10
  • Werkzeug version: 3.0.3
@not-a-kiwi not-a-kiwi linked a pull request Sep 25, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant