Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValueError: too many values to unpack (expected 1) - on version 52.2 #1287

Closed
tomas-zemres opened this issue Jan 20, 2021 · 1 comment
Closed
Labels
crash Problems preventing documents from being rendered
Milestone

Comments

@tomas-zemres
Copy link

I try to upgrade to latest version of WeasyPrint (52.2), but my code raises exception:

ValueError: too many values to unpack (expected 1)
in File weasyprint/css/computed_values.py", line 213, in compute_variable

This error is raised with WeasyPrint version 52.2,
I try with Python 3.8.3 (on Linux)

(note it was working correctly with WeasyPrint version 51)

Try the test-script:

import weasyprint

HTML_DOC = """<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <style>
        :root {
            --content-bottom-right: "Page " counter(page) "/" counter(pages);
        }
        @page {
            @bottom-right{
                content: var(--content-bottom-right);
            }
        }
    </style>
</head>
<body>
    <main>
        test
    </main>
</body>
</html>
"""
weasyprint.HTML(string=HTML_DOC).write_pdf('test.pdf')

It raises following exception:

Traceback (most recent call last):
  File "./test-weasyprint-error.py", line 25, in <module>
    weasyprint.HTML(string=HTML_DOC).write_pdf('test.pdf')
  File ".../lib/python3.8/site-packages/weasyprint/__init__.py", line 222, in write_pdf
    self.render(
  File ".../lib/python3.8/site-packages/weasyprint/__init__.py", line 172, in render
    return Document._render(
  File ".../lib/python3.8/site-packages/weasyprint/document.py", line 406, in _render
    [Page(page_box, enable_hinting) for page_box in page_boxes],
  File ".../lib/python3.8/site-packages/weasyprint/document.py", line 406, in <listcomp>
    [Page(page_box, enable_hinting) for page_box in page_boxes],
  File ".../lib/python3.8/site-packages/weasyprint/layout/__init__.py", line 123, in layout_document
    pages = list(make_all_pages(context, root_box, html, pages))
  File ".../lib/python3.8/site-packages/weasyprint/layout/pages.py", line 800, in make_all_pages
    page, resume_at = remake_page(i, context, root_box, html)
  File ".../lib/python3.8/site-packages/weasyprint/layout/pages.py", line 729, in remake_page
    set_page_type_computed_styles(page_type, html, context.style_for)
  File ".../lib/python3.8/site-packages/weasyprint/layout/pages.py", line 686, in set_page_type_computed_styles
    style_for.set_computed_styles(
  File ".../lib/python3.8/site-packages/weasyprint/css/__init__.py", line 164, in set_computed_styles
    computed_styles[element, pseudo_type] = computed_from_cascaded(
  File ".../lib/python3.8/site-packages/weasyprint/css/__init__.py", line 667, in computed_from_cascaded
    return computed_values.compute(
  File ".../lib/python3.8/site-packages/weasyprint/css/computed_values.py", line 268, in compute
    value[i], already_computed_value = compute_variable(
  File ".../lib/python3.8/site-packages/weasyprint/css/computed_values.py", line 213, in compute_variable
    value, = new_value
ValueError: too many values to unpack (expected 1)
@liZe liZe added the crash Problems preventing documents from being rendered label Jan 20, 2021
@liZe
Copy link
Member

liZe commented Jan 20, 2021

Hello!

Thanks a lot for this report. The bug is caused by #1165, and it once again shows how calculated values are broken in WeasyPrint and prevent a sane use of functions (var for you, but it’s the same for attr).

I’m afraid there’s no easy fix. As explained in #1165, rewriting this whole code is the only solution to fix bugs like this one, and to handle functions correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crash Problems preventing documents from being rendered
Projects
None yet
Development

No branches or pull requests

2 participants