سؤال

Basically , i am saving few feed urls in Django model and for parsing, the urls that i retrieve from model, it is not parsed. Below is how i am trying to query model and parsing a url using feedparser.

>>> from bit.models import *   
>>> url = feednfo.objects.filter(iD=1).values('feed_url')  
>>> url  
>>> [{'feed_url': u'http://www.popgadget.net/atom.xml'}]  
>>> import feedparser as fp  
>>> feed = fp.parse(url)  
>>> feed  
>>>{'feed': {}, 'bozo': 1, 'bozo_exception': TypeError('coercing to Unicode: need string or buffer, ValuesQuerySet found',), 'entries': []}  
>>> feed = fp.parse('http://www.popgadget.net/atom.xml')  
>>> feed.bozo  
>>>0  

Can anyone tell me what is going wrong. Is there any issue regarding string or unicode format?

هل كانت مفيدة؟

المحلول

You are passing a list of dict to feedparser.parse().

That:

feed = fp.parse(url)  

Is like:

feed = fp.parse([{'feed_url': u'http://www.popgadget.net/atom.xml'}])

Should be:

feed = fp.parse(url[0]['feed_url'])

To be like:

feed = fp.parse(u'http://www.popgadget.net/atom.xml')
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top