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

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

Open
muravjov opened this issue Oct 21, 2024 · 1 comment
Open

Comments

@muravjov
Copy link

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
@muravjov
Copy link
Author

See also #71

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

No branches or pull requests

1 participant