Fix crash when stylesheet is not available #84

Closed
wants to merge 2 commits into
from

Conversation

Projects
None yet
2 participants
@ariofrio
Contributor

ariofrio commented May 17, 2013

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

Example: http://www.w3.org/Style/CSS/Test/Print/1.0/20070802/t1302-page-01-b.htm

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

This comment has been minimized.

Show comment
Hide comment
@SimonSapin

SimonSapin Jun 20, 2013

Member

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.

Member

SimonSapin commented Jun 20, 2013

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