简体   繁体   中英

unicode decode error for weasyprint

I try and use weasyprint to prepare a PDF, and with my string, I get the following error. I decode the string to unicode before feeding it to weasyprint. Any suggestions?

'utf8' codec can't decode byte 0xc2 in position 0: unexpected end of data Request Method: GET Django Version: 1.6.2 Exception Type: UnicodeDecodeError Exception Value:
'utf8' codec can't decode byte 0xc2 in position 0: unexpected end of data Exception Location: /usr/lib/python2.7/encodings/utf_8.py in decode, line 16 Python Executable: /usr/bin/python Python Version: 2.7.6 Python Path:

Unicode error hint

The string that could not be encoded/decoded was: Traceback Switch to copy-and-paste view

/usr/local/lib/python2.7/dist-packages/weasyprint/__init__.py in write_pdf
        return self.render(stylesheets).write_pdf(target, zoom, attachments) ...
/usr/local/lib/python2.7/dist-packages/weasyprint/__init__.py in render
        return Document._render(self, stylesheets, enable_hinting) ...
/usr/local/lib/python2.7/dist-packages/weasyprint/document.py in _render
        return cls([Page(p, enable_hinting) for p in page_boxes], ...
/usr/local/lib/python2.7/dist-packages/weasyprint/layout/__init__.py in layout_document
    pages = list(make_all_pages(context, root_box)) ...
/usr/local/lib/python2.7/dist-packages/weasyprint/layout/pages.py in make_all_pages
            context, root_box, page_type, resume_at, content_empty) ...
/usr/local/lib/python2.7/dist-packages/weasyprint/layout/pages.py in make_page
        positioned_boxes, positioned_boxes, adjoining_margins) ...
/usr/local/lib/python2.7/dist-packages/weasyprint/layout/blocks.py in block_level_layout
            absolute_boxes, fixed_boxes, adjoining_margins) ...
/usr/local/lib/python2.7/dist-packages/weasyprint/layout/blocks.py in block_box_layout
            page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins) ...
/usr/local/lib/python2.7/dist-packages/weasyprint/layout/blocks.py in block_container_layout
                    adjoining_margins) ...
/usr/local/lib/python2.7/dist-packages/weasyprint/layout/blocks.py in block_level_layout
            absolute_boxes, fixed_boxes, adjoining_margins) ...
/usr/local/lib/python2.7/dist-packages/weasyprint/layout/blocks.py in block_box_layout
            page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins) ...
/usr/local/lib/python2.7/dist-packages/weasyprint/layout/blocks.py in block_container_layout
                    adjoining_margins) ...
/usr/local/lib/python2.7/dist-packages/weasyprint/layout/blocks.py in block_level_layout
            absolute_boxes, fixed_boxes, adjoining_margins) ...
/usr/local/lib/python2.7/dist-packages/weasyprint/layout/blocks.py in block_box_layout
            page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins) ...
/usr/local/lib/python2.7/dist-packages/weasyprint/layout/blocks.py in block_container_layout
                    adjoining_margins) ...
/usr/local/lib/python2.7/dist-packages/weasyprint/layout/blocks.py in block_level_layout
            absolute_boxes, fixed_boxes, adjoining_margins) ...
/usr/local/lib/python2.7/dist-packages/weasyprint/layout/blocks.py in block_box_layout
            page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins) ...
/usr/local/lib/python2.7/dist-packages/weasyprint/layout/blocks.py in block_container_layout
                    adjoining_margins) ...
/usr/local/lib/python2.7/dist-packages/weasyprint/layout/blocks.py in block_level_layout
            device_size, page_is_empty, absolute_boxes, fixed_boxes) ...
/usr/local/lib/python2.7/dist-packages/weasyprint/layout/tables.py in table_layout
        all_groups_layout() ...
/usr/local/lib/python2.7/dist-packages/weasyprint/layout/tables.py in all_groups_layout
            skip_stack, position_y, max_position_y, page_is_empty) ...
/usr/local/lib/python2.7/dist-packages/weasyprint/layout/tables.py in body_groups_layout
                group, position_y, max_position_y, page_is_empty, skip_stack) /usr/local/lib/python2.7/dist-packages/weasyprint/layout/tables.py in group_layout
                    fixed_boxes=fixed_boxes) ...
/usr/local/lib/python2.7/dist-packages/weasyprint/layout/blocks.py in block_container_layout
                    adjoining_margins) ...
/usr/local/lib/python2.7/dist-packages/weasyprint/layout/blocks.py in block_level_layout
            absolute_boxes, fixed_boxes, adjoining_margins) ...
/usr/local/lib/python2.7/dist-packages/weasyprint/layout/blocks.py in block_box_layout
            page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins) ...
/usr/local/lib/python2.7/dist-packages/weasyprint/layout/blocks.py in block_container_layout
                    adjoining_margins) ...
/usr/local/lib/python2.7/dist-packages/weasyprint/layout/blocks.py in block_level_layout
            absolute_boxes, fixed_boxes, adjoining_margins) ...
/usr/local/lib/python2.7/dist-packages/weasyprint/layout/blocks.py in block_box_layout
            page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins) ...
/usr/local/lib/python2.7/dist-packages/weasyprint/layout/blocks.py in block_container_layout
                    adjoining_margins) ...
/usr/local/lib/python2.7/dist-packages/weasyprint/layout/blocks.py in block_level_layout
            absolute_boxes, fixed_boxes, adjoining_margins) ...
/usr/local/lib/python2.7/dist-packages/weasyprint/layout/blocks.py in block_box_layout
            page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins) ...
/usr/local/lib/python2.7/dist-packages/weasyprint/layout/blocks.py in block_container_layout
                    adjoining_margins) ...
/usr/local/lib/python2.7/dist-packages/weasyprint/layout/blocks.py in block_level_layout
            device_size, page_is_empty, absolute_boxes, fixed_boxes) ...
/usr/local/lib/python2.7/dist-packages/weasyprint/layout/tables.py in table_layout
        all_groups_layout() ...
/usr/local/lib/python2.7/dist-packages/weasyprint/layout/tables.py in all_groups_layout
            skip_stack, position_y, max_position_y, page_is_empty) ...
/usr/local/lib/python2.7/dist-packages/weasyprint/layout/tables.py in body_groups_layout
                group, position_y, max_position_y, page_is_empty, skip_stack) /usr/local/lib/python2.7/dist-packages/weasyprint/layout/tables.py in group_layout
                    fixed_boxes=fixed_boxes) ...
/usr/local/lib/python2.7/dist-packages/weasyprint/layout/blocks.py in block_container_layout
            for line, resume_at in lines_iterator: ...
/usr/local/lib/python2.7/dist-packages/weasyprint/layout/inlines.py in iter_line_boxes
            device_size, absolute_boxes, fixed_boxes) ...
/usr/local/lib/python2.7/dist-packages/weasyprint/layout/inlines.py in get_next_linebox
            line_fixed, line_placeholders, waiting_floats) ...
/usr/local/lib/python2.7/dist-packages/weasyprint/layout/inlines.py in split_inline_box
            waiting_floats) ...
/usr/local/lib/python2.7/dist-packages/weasyprint/layout/inlines.py in split_inline_level
            context, box, max_x - position_x, max_x, skip) ...
/usr/local/lib/python2.7/dist-packages/weasyprint/layout/inlines.py in split_text_box
        text, box.style, context.enable_hinting, available_width, line_width) /usr/local/lib/python2.7/dist-packages/weasyprint/text.py in split_first_line
        first_part = utf8_slice(text, slice(temp_second_line_index)) ...
/usr/local/lib/python2.7/dist-packages/weasyprint/text.py in utf8_slice
    return string.encode('utf-8')[slice_].decode('utf-8') ...
/usr/lib/python2.7/encodings/utf_8.py in decode
    return codecs.utf_8_decode(input, errors, True) ...

Your issue seems to be related to a bug in weasyprint : https://github.com/Kozea/WeasyPrint/issues/285 .

The bug has just been resolved.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM