py3: fix creation of empty record with .txt format

Metadata objects are unicode strings, but we tried to write the content
directly to a .txt file opened in binary mode.
This commit is contained in:
Eli Schwartz 2020-01-07 10:51:16 -05:00
parent 788278b97e
commit cc2eefbb17
No known key found for this signature in database
GPG Key ID: CEB167EFB5722BD6

View File

@ -42,7 +42,7 @@ def create_book(mi, path, fmt='epub', opf_name='metadata.opf', html_name='start.
if fmt == 'txt':
with open(path, 'wb') as f:
if not mi.is_null('title'):
f.write(mi.title)
f.write(mi.title.encode('utf-8'))
return
if fmt == 'docx':
from calibre.ebooks.conversion.plumber import Plumber