Skip to content

fix UnicodeEncodeError on latin-1#844

Open
JervisTetch wants to merge 1 commit intomps-youtube:developfrom
JervisTetch:develop
Open

fix UnicodeEncodeError on latin-1#844
JervisTetch wants to merge 1 commit intomps-youtube:developfrom
JervisTetch:develop

Conversation

@JervisTetch
Copy link

if 'history' in g.userhist:
for song in g.userhist['history'].songs:
hf.write('#EXTINF:%d,%s\n' % (song.length, song.title))
hf.write('#EXTINF:%d,%s\n' % (song.length, song.title.encode('utf-8')))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't look right to me.

Look at the behavior of this code, for instance: "encoded: %s" % ("test".encode("utf8"),). This results in the string "encoded: b'test'". So it produces a str (not bytes) containing b' and '.

I'm not sure the best solution here. If we want to save the file as UTF-8, then we can pass an encoding= argument to open.

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

Successfully merging this pull request may close these issues.

3 participants