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

UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' #82

Closed
hvdwolf opened this issue Mar 1, 2020 · 1 comment
Closed

Comments

@hvdwolf
Copy link

hvdwolf commented Mar 1, 2020

Tested with pysrt 1.0.1 (Debian buster 10.3 and Ubuntu Bionic 18.04 default pkg) and pypip version which is also 1.0.1 (for both debian buster and ubuntu bionic)
I tried with the github version (1.1.2) but somehow I can't make that one work.

I have a series of 6 utf-8 based srt files in Dutch.
If I check them I see

file -i new/Shetland-05x02-Episode2.MTB.srt 
new/Shetland-05x02-Episode2.MTB.srt: text/plain; charset=utf-8

If I try to convert them, I get:

srt shift -36s500ms checkfile.srt > checkfile2.srt 
Traceback (most recent call last):
  File "/usr/bin/srt", line 9, in <module>
    load_entry_point('pysrt==1.0.1', 'console_scripts', 'srt')()
  File "/usr/lib/python2.7/dist-packages/pysrt/commands.py", line 215, in main
    SubRipShifter().run(sys.argv[1:])
  File "/usr/lib/python2.7/dist-packages/pysrt/commands.py", line 136, in run
    self.arguments.action()
  File "/usr/lib/python2.7/dist-packages/pysrt/commands.py", line 155, in shift
    self.input_file.write_into(self.output_file)
  File "/usr/lib/python2.7/dist-packages/pysrt/srtfile.py", line 247, in write_into
    output_file.write(string_repr)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 35: ordinal not in range(128)

The character is "é" in below string (I assume):
Oké, kom mee.

I already tried multiple iconv conversions like

iconv -f utf-8 -t utf-8 file1.srt > file2.srt
iconv -f utf-8 -t iso-8859-1 file1.srt > file2.srt
iconv -f iso-8859-1 -t utf-8 file1.srt > file2.srt

and more (nonsense) conversions, just to try. But none works.

My default python is Python 2.7.16.
When changing to python3 (3.7.3), I get
ModuleNotFoundError: No module named 'pysrt'

@hvdwolf
Copy link
Author

hvdwolf commented Mar 1, 2020

And 20 minutes later ..... :(
After having downloaded the git repo, I did not uninstall the pip and pip3 installed versions correctly.
After having done that and do a sudo python3 ./setup.py install from the git repo, it installs correctly and works correctly.

Sorry for the incorrect issue.

@hvdwolf hvdwolf closed this as completed Mar 1, 2020
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