We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Normally I find that an entry's enclosures property always exists, but is an empty list if the entry has no enclosures.
enclosures
However, if an entry has an id, but no link, then the enclosures property does not exist.
id
link
Three examples of this with Atom feeds (I think it was the same with RSS), using python 3.10 and feedparser 6.0.10:
<?xml version="1.0" encoding="utf-8" ?> <feed xmlns="http://www.w3.org/2005/Atom"> <title>Test feed</title> <link href="https://example.org/"/> <id>https://example.org/</id> <entry> <link>https://example.org/items/1</link> <title>Hello</title> <published>2022-12-07T10:40:00+00:00</published> <summary>Hello.</summary> </entry> </feed>
>>> d = feedparser.parse("https://example.org/test.xml") >>> d.entries[0].enclosures []
<?xml version="1.0" encoding="utf-8" ?> <feed xmlns="http://www.w3.org/2005/Atom"> <title>Test feed</title> <link href="https://example.org/"/> <id>https://example.org/</id> <entry> <link>https://example.org/items/1</link> <id>https://example.org/items/1</id> <title>Hello</title> <published>2022-12-07T10:40:00+00:00</published> <summary>Hello.</summary> </entry> </feed>
<?xml version="1.0" encoding="utf-8" ?> <feed xmlns="http://www.w3.org/2005/Atom"> <title>Test feed</title> <link href="https://example.org/"/> <id>https://example.org/</id> <entry> <id>https://example.org/items/1</id> <title>Hello</title> <published>2022-12-07T10:40:00+00:00</published> <summary>Hello.</summary> </entry> </feed>
>>> d = feedparser.parse("https://example.org/test.xml") >>> d.entries[0].enclosures --------------------------------------------------------------------------- KeyError Traceback (most recent call last) File /usr/local/lib/python3.10/site-packages/feedparser/util.py:156, in FeedParserDict.__getattr__(self, key) 155 try: --> 156 return self.__getitem__(key) 157 except KeyError: File /usr/local/lib/python3.10/site-packages/feedparser/util.py:65, in FeedParserDict.__getitem__(self, key) 62 norel = lambda link: FeedParserDict([(name, value) for (name, value) in link.items() if name != 'rel']) 63 return [ 64 norel(link) ---> 65 for link in dict.__getitem__(self, 'links') 66 if link['rel'] == 'enclosure' 67 ] 68 elif key == 'license': KeyError: 'links' During handling of the above exception, another exception occurred: AttributeError Traceback (most recent call last) Cell In[20], line 1 ----> 1 d.entries[0].enclosures File /usr/local/lib/python3.10/site-packages/feedparser/util.py:158, in FeedParserDict.__getattr__(self, key) 156 return self.__getitem__(key) 157 except KeyError: --> 158 raise AttributeError("object has no attribute '%s'" % key) AttributeError: object has no attribute 'enclosures'
The text was updated successfully, but these errors were encountered:
I agree that this should not crash. I'll work to get this resolved.
Thanks for reporting this!
Sorry, something went wrong.
Hi, any news on this one? This prevents some feeds from being parsed
No branches or pull requests
Normally I find that an entry's
enclosures
property always exists, but is an empty list if the entry has no enclosures.However, if an entry has an
id
, but nolink
, then theenclosures
property does not exist.Three examples of this with Atom feeds (I think it was the same with RSS), using python 3.10 and feedparser 6.0.10:
1. Has
link
but noid
-enclosures
property exists2. Has both
link
andid
-enclosures
property exists3. Has
id
but nolink
-enclosures
property does not existThe text was updated successfully, but these errors were encountered: