0

I'm fairly new to Django and Python. I'm trying to build small RSS reader using feedparser. I'm getting this error and I can't seem to find any solutions anywhere

{'feed': {}, 'bozo': 1, 'bozo_exception': TypeError("'Feed' does not have the buffer interface",), 'entries': []}

Here are files which are involved (simplified version to ilustrate the problem)

## models
class Feed(models.Model):
    name = models.CharField(max_length=100)
    url = models.CharField(max_length=100)
    category = models.ForeignKey(Category)
    user = models.ManyToManyField(User)

    def __unicode__(self):
        return self.url

## views
def feed5(request):
    source = Feed.objects.get(id=1)
    rss = feedparser.parse(source)
    context = {
    'rss': rss,
    }
    return render(request, 'feedreader/feed5.html', context)


## feed5.html
{% block content %}

{{ rss }}

<p><a href ="{{ rss.feed.link }}">{{ rss.feed.title }}</a></p>

<ul>
{% for r in rss.entries|slice:":10" %}
<li> <a class="title" href="{{ r.link }}">{{ r.title }}</a> <br />{{ r.description }}</li>
{% endfor %}
</ul>

{% endblock %}

When I try to manually enter rss feed here

## views
def feed5(request):
    source = Feed.objects.get(id=1)
    **rss = feedparser.parse('http://rss.gazeta.pl/pub/rss/wiadomosci.htm')**
    context = {
    'rss': rss,
    }
    return render(request, 'feedreader/feed5.html', context)

It works fine, but when I pull it from DB, it doesn't work.

I went over this http://pythonhosted.org/feedparser/character-encoding.html and this feedparser fails during script run, but can't reproduce in interactive python console

but I can't figure it out. Would any of be able to help ?

thanks sikor

Community
  • 1
  • 1
sikor
  • 143
  • 2
  • 10

1 Answers1

1

You should provide source.url not source to the feedparser

Ilian Iliev
  • 3,217
  • 4
  • 26
  • 51
  • Aha ! That worked, altho I'm still too new to this to fully understand why :) – sikor Sep 29 '13 at 13:27
  • Many thanks for this tip. Would you mind helping me also with the next step? Now I would like to iterate through many feeds from models/DB and have each of them displayed in the html template. While I do understand that I need to iterate thought x.feed.entries in the html template, I assume that iteration through each rss source needs to happen in the view function correct? – sikor Sep 29 '13 at 13:30
  • Actually I've added code example to this follow question here http://stackoverflow.com/questions/19078710/queryset-object-has-no-attribute-url-when-using-feedparser-in-django – sikor Sep 29 '13 at 13:42