feedparser icon indicating copy to clipboard operation
feedparser copied to clipboard

KeyError '__deepcopy__'

Open decaz opened this issue 7 years ago • 2 comments

There are several places where deepcopy is used with FeedParserDict instance. It raises KeyError since there is a row copier = getattr(x, "__deepcopy__", None) within copy.deepcopy function:

KeyError: '__deepcopy__'
  File "site-packages/feedparser.py", line 398, in __getattr__
    return self.__getitem__(key)
  File "site-packages/feedparser.py", line 356, in __getitem__
    return dict.__getitem__(self, key)

I have found the old commit https://github.com/kurtmckee/feedparser/commit/ba2e85eab38ddf5f909091d205dcf13770539d68 but now there is no any check to prevent such a case.

decaz avatar Apr 09 '18 17:04 decaz

Thanks for reporting this! I'd like to confirm the behavior: is the KeyError happening in code that you've written? Or is it happening while parsing a specific feed? Finally, what version of Python are you using?

kurtmckee avatar Apr 27 '18 19:04 kurtmckee

@kurtmckee the KeyError happens while parsing some feeds and unfortunately it's hard to catch it - it's very rare. Sentry says the error is raising at https://github.com/kurtmckee/feedparser/blob/develop/feedparser/util.py#L97 with the following locals:

key = '__deepcopy__'
realkey = '__deepcopy__'
self = {
    'base': '', 
    'language': None, 
    'type': 'text/plain'
}

I use Python 3.6.4.

decaz avatar May 09 '18 10:05 decaz