Skip to content

error_handling=SubRipFile.ERROR_LOG mode causes exceptions in Python3 #98

@muravjov

Description

@muravjov

Hi,
I open .srt files with error_handling=SubRipFile.ERROR_LOG, and it works fine in Py2 but not in Py3.

In case of a wrongly formatted srt file pysrt tries to write bytes into sys.stderr:

            sys.stderr.write(error.args[0].encode('ascii', 'replace'))

So we get in Py3:

  File "/Users/ilya/opt/programming/catbo/backend-env11/lib/python3.11/site-packages/pysrt/srtfile.py", line 153, in open
    new_file.read(source_file, error_handling=error_handling)
  File "/Users/ilya/opt/programming/catbo/backend-env11/lib/python3.11/site-packages/pysrt/srtfile.py", line 181, in read
    self.extend(self.stream(source_file, error_handling=error_handling))
  File "/opt/homebrew/Cellar/[email protected]/3.11.7/Frameworks/Python.framework/Versions/3.11/lib/python3.11/collections/__init__.py", line 1324, in extend
    self.data.extend(other)
  File "/Users/ilya/opt/programming/catbo/backend-env11/lib/python3.11/site-packages/pysrt/srtfile.py", line 215, in stream
    cls._handle_error(error, error_handling, index)
  File "/Users/ilya/opt/programming/catbo/backend-env11/lib/python3.11/site-packages/pysrt/srtfile.py", line 311, in _handle_error
    sys.stderr.write(error.args[0].encode('ascii', 'replace'))
TypeError: write() argument must be str, not bytes

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions