diff --git a/src/calibre/ebooks/oeb/polish/check/opf.py b/src/calibre/ebooks/oeb/polish/check/opf.py index 76f8418b4e..e2f6abd0e3 100644 --- a/src/calibre/ebooks/oeb/polish/check/opf.py +++ b/src/calibre/ebooks/oeb/polish/check/opf.py @@ -370,7 +370,7 @@ def check_opf(container): errors.append(IncorrectCover(container.opf_name, cover.sourceline, cover.get('content', ''))) raw = etree.tostring(cover) try: - n, c = raw.index('name="'), raw.index('content="') + n, c = raw.index(b'name="'), raw.index(b'content="') except ValueError: n = c = -1 if n > -1 and c > -1 and n > c: diff --git a/src/calibre/ebooks/oeb/polish/cover.py b/src/calibre/ebooks/oeb/polish/cover.py index 941ef71d17..b84a938a94 100644 --- a/src/calibre/ebooks/oeb/polish/cover.py +++ b/src/calibre/ebooks/oeb/polish/cover.py @@ -393,8 +393,10 @@ def create_epub_cover(container, cover_path, existing_image, options=None): titlepage_item = container.generate_item(tname, id_prefix='titlepage') titlepage = container.href_to_name(titlepage_item.get('href'), container.opf_name) - raw = templ%container.name_to_href(raster_cover, titlepage).encode('utf-8') + raw = templ % container.name_to_href(raster_cover, titlepage) with container.open(titlepage, 'wb') as f: + if not isinstance(raw, bytes): + raw = raw.encode('utf-8') f.write(raw) # We have to make sure the raster cover item has id="cover" for the moron