It's "dangerous" to assume that every requests.get(url) works out perfectly.
This PR makes that a bit more explicit and louder if it does fail to download a URL correctly.
Sample traceback:
Traceback (most recent call last):
File "dummy.py", line 31, in <module>
print(premailer.transform(html, cssutils_logging_level=logging.ERROR))
File "/Users/peterbe/dev/PYTHON/premailer/premailer/premailer.py", line 670, in transform
return Premailer(**kwargs).transform(html, pretty_print=pretty_print)
File "/Users/peterbe/dev/PYTHON/premailer/premailer/premailer.py", line 374, in transform
css_body = self._load_external(href)
File "/Users/peterbe/dev/PYTHON/premailer/premailer/premailer.py", line 551, in _load_external
css_body = self._load_external_url(url)
File "/Users/peterbe/dev/PYTHON/premailer/premailer/premailer.py", line 537, in _load_external_url
response.raise_for_status()
File "/Users/peterbe/virtualenvs/premailer/lib/python3.6/site-packages/requests/models.py", line 940, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 404 Client Error: Not Found for url: https://www.peterbe.com/static/css/base.min.79787297dbf5.csxxxxs
Coverage remained the same at 100.0% when pulling cff33958b128b6481ca0f5a8e0cb6ee6424d23ff on better-http-error-caching-when-downloading into 03e8848a3de8118e127b7077ae35c25cb843c496 on master.
Coverage remained the same at 100.0% when pulling cff33958b128b6481ca0f5a8e0cb6ee6424d23ff on better-http-error-caching-when-downloading into 03e8848a3de8118e127b7077ae35c25cb843c496 on master.
It's "dangerous" to assume that every
requests.get(url)
works out perfectly. This PR makes that a bit more explicit and louder if it does fail to download a URL correctly.Sample traceback: