Repository: scottwernervt/favicon

Issue:
AttributeError: 'NoneType' object has no attribute 'lower'
The following tag `<meta content="en-US" data-rh="true" itemprop="inLanguage"/>` causes an exception because it does not have `name` or `proprety` attribute.

```python
Traceback (most recent call last):
  File "/opt/pycharm-professional/helpers/pydev/pydevd.py", line 1664, in <module>
    main()
  File "/opt/pycharm-professional/helpers/pydev/pydevd.py", line 1658, in main
    globals = debugger.run(setup['file'], None, None, is_module)
  File "/opt/pycharm-professional/helpers/pydev/pydevd.py", line 1068, in run
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "/opt/pycharm-professional/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "/home/swerner/development/projects/favicon/debug.py", line 3, in <module>
    fav_icons = favicon.get('https://www.nytimes.com/')
  File "/home/swerner/development/projects/favicon/src/favicon/favicon.py", line 69, in get
    link_icons = tags(response.url, response.text)
  File "/home/swerner/development/projects/favicon/src/favicon/favicon.py", line 125, in tags
    if meta_type.lower() == name.lower():
AttributeError: 'NoneType' object has no attribute 'lower'
```

Discussion:

Patch:
diff --git a/CHANGELOG.rst b/CHANGELOG.rst
index d1cc7ff..f17f3d6 100644
--- a/CHANGELOG.rst
+++ b/CHANGELOG.rst
@@ -1,6 +1,11 @@
 Changelog
 =========
 
+0.5.1 (2018-11-05)
+------------------
+
+* Fix 'NoneType' object has no attribute 'lower' for meta tags (`#16 <https://github.com/scottwernervt/favicon/issues/16>`_).
+
 0.5.0 (2018-11-05)
 ------------------
 
diff --git a/src/favicon/favicon.py b/src/favicon/favicon.py
index cd18532..df5eaf7 100644
--- a/src/favicon/favicon.py
+++ b/src/favicon/favicon.py
@@ -120,9 +120,10 @@ def tags(url, html):
 
     meta_tags = set()
     for meta_tag in soup.find_all('meta', attrs={'content': True}):
-        meta_type = meta_tag.get('name') or meta_tag.get('property')
+        meta_type = meta_tag.get('name') or meta_tag.get('property') or ''
+        meta_type = meta_type.lower()
         for name in META_NAMES:
-            if meta_type.lower() == name.lower():
+            if meta_type == name.lower():
                 meta_tags.add(meta_tag)
 
     icons = set()


Test patch:
diff --git a/tests/test_favicon.py b/tests/test_favicon.py
index 6551313..ffa32c0 100644
--- a/tests/test_favicon.py
+++ b/tests/test_favicon.py
@@ -116,6 +116,15 @@ def test_meta_content_attribute(m, meta_tag):
     assert icons
 
 
+def test_invalid_meta_tag(m):
+    m.head('http://mock.com/favicon.ico', text='Not Found', status_code=404)
+    m.get('http://mock.com/',
+          text='<meta content="en-US" data-rh="true" itemprop="inLanguage"/>')
+
+    icons = favicon.get('http://mock.com/')
+    assert not icons
+
+
 @pytest.mark.parametrize('url,expected', [
     ('http://mock.com/favicon.ico', True),
     ('favicon.ico', False),