WeasyPrint: CAIRO_STATUS_TAG_ERROR: b'invalid tag name, attributes, or nesting'
Hello,
I encountered a strange error. When I try to render a pdf in my flask app with the following code:
@some_blueprint.route("/print/<string:file_hash>")
def print_pdf(file_hash):
html = HTML(string="<html><head><title>Test</title></head><body><h1>test</h1></body></html>")
return render_pdf(html)
Then I get:
Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/flask/app.py", line 2309, in __call__
return self.wsgi_app(environ, start_response)
File "/usr/local/lib/python3.6/dist-packages/flask/app.py", line 2295, in wsgi_app
response = self.handle_exception(e)
File "/usr/local/lib/python3.6/dist-packages/flask/app.py", line 1741, in handle_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python3.6/dist-packages/flask/_compat.py", line 35, in reraise
raise value
File "/usr/local/lib/python3.6/dist-packages/flask/app.py", line 2292, in wsgi_app
response = self.full_dispatch_request()
File "/usr/local/lib/python3.6/dist-packages/flask/app.py", line 1815, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/local/lib/python3.6/dist-packages/flask/app.py", line 1718, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python3.6/dist-packages/flask/_compat.py", line 35, in reraise
raise value
File "/usr/local/lib/python3.6/dist-packages/flask/app.py", line 1813, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/local/lib/python3.6/dist-packages/flask/app.py", line 1799, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/azk/azk/controllers/hiwi.py", line 184, in print_pdf
return render_pdf(html)
File "/usr/local/lib/python3.6/dist-packages/flask_weasyprint/__init__.py", line 209, in render_pdf
pdf = html.write_pdf(stylesheets=stylesheets)
File "/usr/local/lib/python3.6/dist-packages/weasyprint/__init__.py", line 199, in write_pdf
target, zoom, attachments)
File "/usr/local/lib/python3.6/dist-packages/weasyprint/document.py", line 613, in write_pdf
levels.pop(), title, link_attribs, 0)
File "/usr/local/lib/python3.6/dist-packages/cairocffi/surfaces.py", line 903, in add_outline
self._check_status()
File "/usr/local/lib/python3.6/dist-packages/cairocffi/surfaces.py", line 160, in _check_status
_check_status(cairo.cairo_surface_status(self._pointer))
File "/usr/local/lib/python3.6/dist-packages/cairocffi/__init__.py", line 79, in _check_status
raise exception(message, status)
cairocffi.CairoError: cairo returned CAIRO_STATUS_TAG_ERROR: b'invalid tag name, attributes, or nesting'
Actually I am using flask_weasyprint, but the error is the same when using weasyprint directly. So far I have not been able to reproduce this with a simple flask application, but after removing the <h1> and </h1> tag everythings fine.
My python env consists of:
alembic==1.0.2
asn1crypto==0.24.0
bcrypt==3.1.4
blinker==1.4
bokeh==1.0.1
cairocffi==0.9.0
CairoSVG==2.2.1
certifi==2018.10.15
cffi==1.11.5
chardet==3.0.4
Click==7.0
coverage==4.5.1
cryptography==2.1.4
cssselect2==0.2.1
decorator==4.3.0
defusedxml==0.5.0
Flask==1.0.2
Flask-Bcrypt==0.7.1
Flask-DebugToolbar==0.10.1
Flask-Login==0.4.1
Flask-Migrate==2.3.0
flask-mongoengine==0.9.5
Flask-Principal==0.4.0
Flask-SQLAlchemy==2.3.2
Flask-WeasyPrint==0.5
Flask-WTF==0.14.2
html5lib==1.0.1
idna==2.6
infinity==1.4
intervals==0.8.1
itsdangerous==1.1.0
Jinja2==2.10
keyring==10.6.0
keyrings.alt==3.0
ldap==1.0.2
ldap3==2.5.1
Mako==1.0.7
MarkupSafe==1.1.0
mongoengine==0.16.0
numpy==1.15.4
packaging==18.0
pandas==0.23.4
Pillow==5.3.0
ply==3.11
pyasn1==0.4.4
pyasn1-modules==0.2.2
pycparser==2.18
pycrypto==2.6.1
pygobject==3.26.1
pymongo==3.7.2
PyMySQL==0.9.2
pyparsing==2.3.0
Pyphen==0.9.5
python-dateutil==2.7.5
python-editor==1.0.3
python-ldap==3.1.0
pytz==2018.7
pyxdg==0.25
PyYAML==3.13
regex==2018.11.7
requests==2.20.0
SecretStorage==2.3.1
six==1.11.0
SQLAlchemy==1.2.12
SQLAlchemy-Utils==0.33.6
tinycss2==0.6.1
tornado==5.1.1
urllib3==1.24.1
validators==0.12.2
WeasyPrint==43
webencodings==0.5.1
Werkzeug==0.14.1
WTForms==2.2.1
WTForms-Alchemy==0.16.7
WTForms-Components==0.10.3
and the whole app is running in a docker container which is based on ubuntu 18.04. Is there anything I am doing wrong?
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 44 (39 by maintainers)
Commits related to this issue
- Localize floats used by Cairo tags According to the documentation (and to the code), Cairo seems to rely on locale-dependent strings for tag attributes. It's for sure a bad idea, but at least try to ... — committed to Kozea/WeasyPrint by liZe 6 years ago
- Use font_map_set_default instead of set_font_map Related to #742. — committed to Kozea/WeasyPrint by liZe 6 years ago
- Don't localize numbers on Windows Related to #742. — committed to Kozea/WeasyPrint by liZe 6 years ago
Or…
As Adrian says (and I think he’s right),
%fdoesn’t insert thousands separators. As the only problem we have is the decimal separators (right?), we can just remove the decimal part. The greatest error we can have is 0.5pt (0.18mm), maybe that’s an error we can live with.https://gitlab.freedesktop.org/cairo/cairo/issues/347