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

Fix crash when stylesheet is not available #84

wants to merge 2 commits into from


Copy link

All browsers ignore unavailable stylesheets and print a message to the console to this effect. Instead, WeasyPrint crashes.


Traceback (most recent call last):
  File "/home/ariofrio/Repositories/WeasyPrint/env/bin/weasyprint", line 8, in <module>
    load_entry_point('WeasyPrint==0.19.1', 'console_scripts', 'weasyprint')()
  File "/home/ariofrio/Repositories/WeasyPrint/weasyprint/", line 141, in main
    getattr(html, 'write_' + format_)(output, **kwargs)
  File "/home/ariofrio/Repositories/WeasyPrint/weasyprint/", line 159, in write_pdf
    return self.render(stylesheets).write_pdf(target, zoom)
  File "/home/ariofrio/Repositories/WeasyPrint/weasyprint/", line 131, in render
    return Document._render(self, stylesheets, enable_hinting)
  File "/home/ariofrio/Repositories/WeasyPrint/weasyprint/", line 253, in _render
    for css in stylesheets or []])
  File "/home/ariofrio/Repositories/WeasyPrint/weasyprint/css/", line 431, in get_all_computed_styles
    element_tree, device_media_type, url_fetcher))
  File "/home/ariofrio/Repositories/WeasyPrint/weasyprint/css/", line 189, in find_stylesheets
    _check_mime_type=True, media_type=device_media_type)
  File "/home/ariofrio/Repositories/WeasyPrint/weasyprint/", line 219, in __init__
  File "/home/ariofrio/Repositories/WeasyPrint/weasyprint/", line 271, in _select_source
    result = url_fetcher(url)
  File "/home/ariofrio/Repositories/WeasyPrint/weasyprint/", line 281, in wrapped_fetcher
    result = url_fetcher(url)
  File "/home/ariofrio/Repositories/WeasyPrint/weasyprint/", line 281, in wrapped_fetcher
    result = url_fetcher(url)
  File "/home/ariofrio/Repositories/WeasyPrint/weasyprint/", line 262, in default_url_fetcher
    url, headers={'User-Agent': VERSION_STRING}))
  File "/home/ariofrio/Repositories/WeasyPrint/weasyprint/", line 80, in urlopen_contenttype
    result = urlopen(url)
  File "/usr/lib64/python2.7/", line 126, in urlopen
    return, data, timeout)
  File "/usr/lib64/python2.7/", line 406, in open
    response = meth(req, response)
  File "/usr/lib64/python2.7/", line 519, in http_response
    'http', request, response, code, msg, hdrs)
  File "/usr/lib64/python2.7/", line 444, in error
    return self._call_chain(*args)
  File "/usr/lib64/python2.7/", line 378, in _call_chain
    result = func(*args)
  File "/usr/lib64/python2.7/", line 527, in http_error_default
    raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 404: Not Found

Copy link

Hi, thanks for contributing.

I ended up taking another approach to fix this, but please preserve the indentation style of the file you’re editing. In WeasyPrint we try to follow PEP 8 style, where indentation is always four spaces.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet

Successfully merging this pull request may close these issues.

None yet

2 participants