0

我尝试使用 weasyprint 准备 PDF,并且使用我的字符串,我收到以下错误。在将字符串输入 weasyprint 之前,我将字符串解码为 un​​icode。有什么建议么?

“utf8”编解码器无法解码位置 0 中的字节 0xc2:数据意外结束请求方法:GET Django 版本:1.6.2 异常类型:UnicodeDecodeError 异常值:
“utf8”编解码器无法解码位置 0 中的字节 0xc2:意外数据结束异常位置:解码中的 /usr/lib/python2.7/encodings/utf_8.py 第 16 行 Python 可执行文件:/usr/bin/python Python 版本:2.7.6 Python 路径:

Unicode 错误提示

无法编码/解码的字符串是: · Traceback 切换到复制和粘贴视图

/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) ...
4

1 回答 1

-1

您的问题似乎与 weasyprint 中的错误有关:https ://github.com/Kozea/WeasyPrint/issues/285 。

该错误刚刚解决。

于 2015-12-17T09:40:02.683 回答