peterbe / premailer

Turns CSS blocks into style attributes
https://premailer.io
BSD 3-Clause "New" or "Revised" License
1.06k stars 188 forks source link

AttributeError: 'CSSUnknownRule' object has no attribute 'style' in _css_rules_to_string #201

Closed lavr closed 5 years ago

lavr commented 5 years ago

Exception on complicated style sheet:

>> from premailer import Premailer; import requests; url='https://www.smashingmagazine.com'; Premailer(html=requests.get(url).content.decode('utf-8'), base_url=url).transform()

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/lavr/dev/.env/lib/python3.6/site-packages/premailer/premailer.py", line 358, in transform
    style.text = self._css_rules_to_string(these_leftover)
  File "/Users/lavr/dev/.env/lib/python3.6/site-packages/premailer/premailer.py", line 613, in _css_rules_to_string
    for key in rule.style.keys():
AttributeError: 'CSSUnknownRule' object has no attribute 'style'

I know it's not usual source for email, but seems it covers some cssutils internals and might be easy to fix.

TZanke commented 5 years ago

I discovered this bug also, any Pull request active?

Found pull request by myself https://github.com/peterbe/premailer/pull/202