2
votes

Hello I am getting the following error when using Feedparser:

raise UndeclaredNamespace, "'%s' is not associated with a namespace" % givenprefix feedparser.UndeclaredNamespace: 'media' is not associated with a namespace

I have managed to narrow it down to one feed which is the cause:

http://feeds.mashable.com/Mashable

I am writing a web scraper which uses Feedparser and Beautiful soup to scrape news articles from various rss feed that I am interested in, I am writing this using Python.

The error message is this:

feed = feedparser.parse(in_feed)
File "/usr/lib/python2.7/dist-packages/feedparser.py", line 4014, in parse
saxparser.parse(source)
File "/usr/lib/python2.7/dist-packages/drv_libxml2.py", line 208, in parse
eltName,eltQName,attributesNSImpl) 
File "/usr/lib/python2.7/dist-packages/feedparser.py", line 1809, in startElementNS
raise UndeclaredNamespace, "'%s' is not associated with a namespace" % givenprefix
feedparser.UndeclaredNamespace: 'media' is not associated with a namespace 

All other feeds are ok. Can someone give me some advice regarding this please.

1
What code are you executing when the exception is thrown?bbayles
I am running 'feed = feedparser.parse(in_feed)' where in_feed=feeds.mashable.com/Mashabletimebandit

1 Answers

1
votes

I looked at the Mashable feed and it has at the top all the imported namespaces:

<rss version='2.0' xmlns:atom='http://www.w3.org/2005/Atom' xmlns:campaign='http://organizecampaign.com/' xmlns:content='http://purl.org/rss/1.0/modules/content/' xmlns:dc='http://purl.org/dc/elements/1.1/' xmlns:mash='http://mashable.com/rss' xmlns:mashable='http://mashable.com/rss' xmlns:slash='http://purl.org/rss/1.0/modules/slash/' xmlns:sy='http://purl.org/rss/1.0/modules/syndication/' xmlns:wfw='http://wellformedweb.org/CommentAPI/'>

There is no namespace defined for "media", which is why when the tag "media:thumbnail" is encountered later on, an error is thrown.

I would therefore say that Mashable feed is wrongly formed. One way to solve it is to use a public namespace for media. I found one reference at http://www.rssboard.org/media-rss. They give an example:

xmlns:media="http://search.yahoo.com/mrss/"