Skip to content

logger: backslashreplace stream encoding errors #6081

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

Merged
merged 1 commit into from
Jul 14, 2024

Conversation

bastimeyer
Copy link
Member

Follow-up of #6080

This prevents potential character encoding errors on the logger's default streams, stdout and stderr, depending on the default stream encoding.


master

$ PYTHONIOENCODING=ascii streamlink -l debug -p mpv -a '"--title=🐻"' httpstream://file:///dev/zero best
[cli][debug] OS:         Linux-6.9.9-1-git-x86_64-with-glibc2.39
[cli][debug] Python:     3.12.4
[cli][debug] OpenSSL:    OpenSSL 3.3.1 4 Jun 2024
[cli][debug] Streamlink: 6.8.3+1.g09c19cf8
[cli][debug] Dependencies:
[cli][debug]  certifi: 2024.7.4
[cli][debug]  isodate: 0.6.1
[cli][debug]  lxml: 5.2.2
[cli][debug]  pycountry: 24.6.1
[cli][debug]  pycryptodome: 3.20.0
[cli][debug]  PySocks: 1.7.1
[cli][debug]  requests: 2.32.3
[cli][debug]  trio: 0.26.0
[cli][debug]  trio-websocket: 0.11.1
[cli][debug]  typing-extensions: 4.12.2
[cli][debug]  urllib3: 2.2.2
[cli][debug]  websocket-client: 1.8.0
[cli][debug] Arguments:
[cli][debug]  url=httpstream://file:///dev/zero
[cli][debug]  stream=['best']
[cli][debug]  --loglevel=debug
[cli][debug]  --player=mpv
--- Logging error ---
Traceback (most recent call last):
  File "/usr/lib/python3.12/logging/__init__.py", line 1163, in emit
    stream.write(msg + self.terminator)
UnicodeEncodeError: 'ascii' codec can't encode character '\U0001f43b' in position 37: ordinal not in range(128)
Call stack:
  File "/home/basti/venv/streamlink-312/bin/streamlink", line 8, in <module>
    sys.exit(main())
  File "/home/basti/repos/streamlink/src/streamlink_cli/main.py", line 953, in main
    setup(parser)
  File "/home/basti/repos/streamlink/src/streamlink_cli/main.py", line 889, in setup
    log_current_arguments(streamlink, parser)
  File "/home/basti/repos/streamlink/src/streamlink_cli/main.py", line 829, in log_current_arguments
    log.debug(f" {name}={value if name not in sensitive else '*' * 8}")
Message: ' --player-args="--title=\U0001f43b"'
Arguments: ()
[cli][info] Found matching plugin http for URL httpstream://file:///dev/zero
[plugins.http][debug] URL=file:///dev/zero; params={}
[cli][info] Available streams: live (worst, best)
[cli][info] Opening stream: live (http)
[cli][info] Starting player: mpv
[cli][debug] Pre-buffering 8192 bytes
--- Logging error ---
Traceback (most recent call last):
  File "/usr/lib/python3.12/logging/__init__.py", line 1163, in emit
    stream.write(msg + self.terminator)
UnicodeEncodeError: 'ascii' codec can't encode character '\U0001f43b' in position 133: ordinal not in range(128)
Call stack:
  File "/home/basti/venv/streamlink-312/bin/streamlink", line 8, in <module>
    sys.exit(main())
  File "/home/basti/repos/streamlink/src/streamlink_cli/main.py", line 955, in main
    exit_code = run(parser)
  File "/home/basti/repos/streamlink/src/streamlink_cli/main.py", line 927, in run
    handle_url()
  File "/home/basti/repos/streamlink/src/streamlink_cli/main.py", line 564, in handle_url
    handle_stream(plugin, streams, stream_name)
  File "/home/basti/repos/streamlink/src/streamlink_cli/main.py", line 436, in handle_stream
    success = output_stream(stream, formatter)
  File "/home/basti/repos/streamlink/src/streamlink_cli/main.py", line 349, in output_stream
    output.open()
  File "/home/basti/repos/streamlink/src/streamlink_cli/output/abc.py", line 9, in open
    self._open()
  File "/home/basti/repos/streamlink/src/streamlink_cli/output/player.py", line 255, in _open
    self._open_subprocess(args)
  File "/home/basti/repos/streamlink/src/streamlink_cli/output/player.py", line 271, in _open_subprocess
    log.debug(f"Opening subprocess: {args!r}{f', env: {self.env!r}' if self.env else ''}")
Message: "Opening subprocess: ['/home/basti/.local/bin/mpv', '--force-media-title=httpstream://file:///dev/zero', '--title=\U0001f43b', '-']"
Arguments: ()
[cli][debug] Writing stream to output
[cli][info] Player closed
[cli][info] Stream ended
[cli][info] Closing currently open stream...

PR

$ PYTHONIOENCODING=ascii streamlink -l debug -p mpv -a '"--title=🐻"' httpstream://file:///dev/zero best
[cli][debug] OS:         Linux-6.9.9-1-git-x86_64-with-glibc2.39
[cli][debug] Python:     3.12.4
[cli][debug] OpenSSL:    OpenSSL 3.3.1 4 Jun 2024
[cli][debug] Streamlink: 6.8.3+2.g140c62da
[cli][debug] Dependencies:
[cli][debug]  certifi: 2024.7.4
[cli][debug]  isodate: 0.6.1
[cli][debug]  lxml: 5.2.2
[cli][debug]  pycountry: 24.6.1
[cli][debug]  pycryptodome: 3.20.0
[cli][debug]  PySocks: 1.7.1
[cli][debug]  requests: 2.32.3
[cli][debug]  trio: 0.26.0
[cli][debug]  trio-websocket: 0.11.1
[cli][debug]  typing-extensions: 4.12.2
[cli][debug]  urllib3: 2.2.2
[cli][debug]  websocket-client: 1.8.0
[cli][debug] Arguments:
[cli][debug]  url=httpstream://file:///dev/zero
[cli][debug]  stream=['best']
[cli][debug]  --loglevel=debug
[cli][debug]  --player=mpv
[cli][debug]  --player-args="--title=\U0001f43b"
[cli][info] Found matching plugin http for URL httpstream://file:///dev/zero
[plugins.http][debug] URL=file:///dev/zero; params={}
[cli][info] Available streams: live (worst, best)
[cli][info] Opening stream: live (http)
[cli][info] Starting player: mpv
[cli][debug] Pre-buffering 8192 bytes
[cli.output][debug] Opening subprocess: ['/home/basti/.local/bin/mpv', '--force-media-title=httpstream://file:///dev/zero', '--title=\U0001f43b', '-']
[cli][debug] Writing stream to output
[cli][info] Player closed
[cli][info] Stream ended
[cli][info] Closing currently open stream...

@bastimeyer bastimeyer force-pushed the logger/fix-encoding-errors branch from 140c62d to 622a01c Compare July 14, 2024 00:46
@bastimeyer bastimeyer merged commit ab30b0c into streamlink:master Jul 14, 2024
23 checks passed
@bastimeyer bastimeyer deleted the logger/fix-encoding-errors branch July 14, 2024 00:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant