aag / apple_trailer_downloader

A script to download HD trailers from the Apple Trailers website.
GNU General Public License v3.0
23 stars 5 forks source link

Multibyte character handling error #21

Closed forthrin closed 2 years ago

forthrin commented 3 years ago
  File "apple_trailer_downloader/download_trailers.py", line 196, in file_already_downloaded
    trailer_prefix = '{}.trailer'.format(clean_title.lower())
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 8: ordinal not in range(128)
aag commented 3 years ago

Hi forthrin, thanks for the bug report. Which version of Python are you using to run the script? Also, did the script print out the URL of the trailer it was trying to download when the error happened?

forthrin commented 3 years ago
$ python --version
Python 2.7.16

clean_title = 'The Protégé'

kapps7 commented 2 years ago

Sounds like the same issue

Traceback (most recent call last): File "download_trailers.py", line 599, in <module> main() File "download_trailers.py", line 595, in main download_trailers_from_page(url, settings) File "download_trailers.py", line 278, in download_trailers_from_page settings['video_types']) File "download_trailers.py", line 194, in file_already_downloaded trailer_prefix = '{}.trailer'.format(clean_title.lower()) UnicodeEncodeError: 'ascii' codec can't encode character u'\xf4' in position 5: ordinal not in range(128)

forthrin commented 2 years ago

Inserting sys.setdefaultencoding('utf8') (plus some dependencies) at the top of the script resolved the issue for me.

aag commented 2 years ago

Unfortunately I'm not able to reproduce these crashes, so I don't think I'll be able to fix them. The trailer for film "The Protégé" downloads correctly on my machine. It looks like @forthrin has a possible solution that you can use. Alternatively, I'd encourage you to use Python 3 to run the script. Python 2 reached end of life more than a year ago, and Python 3 uses UTF-8 as the default encoding, so this class of problems shouldn't occur.