Search code examples
weasyprint

WeasyPrint unable to load images/css: Temporary failure in name resolution


I'm using WeasyPrint 52.3 (latest version available at time of writing) along with Django 2.2 LTS on Python 3.6 on a Windows 10 development machine; all is working fine.

However when I try to render a PDF on my Linux machine (same WeasyPrint/Django/Python versions), all items I try to load from an URI are not shown, including images and CSS. When not using WeasyPrint, images/CSS are properly loaded. My images/CSS are available at https://myhost.tld/some.css and myhost has its certs signed.

When using inline CSS, the CSS is rendered fine.

I've tried to enable WeasyPrint logging through:

import logging
logger = logging.getLogger('weasyprint')
logger.addHandler(logging.FileHandler('/tmp/weasyprint.log'))

and I see following output:

Failed to load stylesheet at https://myhost.tld/assets/css/pdf.css : URLError: <urlopen error [Errno -3] Temporary failure in name resolution>

How can this be? My DNS system is properly set up for myhost.tld.


Solution

  • Ensure myhost.tld is part of the /etc/hosts file:

    127.0.0.1 localhost
    127.0.1.1 myhost
    127.0.2.1 myhost.tld
    

    Restart the right services and the files will load.