my flask application gives a ‘set’ error I have been coding a RSS feed web app but currently am having an error that I cant figure out; this is my code :
import feedparser
from flask import Flask
from flask import render_template
app = Flask(__name__)
RSS = {"http://feeds.bbci.co.uk/news/rss.xml",
"http://rss.iol.io/iol/news", "http://feeds.foxnews.com/foxnews/latest", "http://rss.cnn.com/rss/edition.rss"}
#error occurs here
@app.route("/")
@app.route("/<publication>")
def get_news(publication="bbc"):
#ERROR OCCURS HERE
feed = feedparser.parse(RSS[publication])
first_article = feed['entries'][0]
return render_template("home.html",
title=first_article.get("title"),
published=first_article.get("publication"),
summary=first_article.get("summary"))
if __name__ == "__main__":
app.run(debug=True, port=5000)
I get my error at these two lines
feed = feedparser.parse(RSS[publication])
first_article = feed['entries'][0]
can’t figure out the actual error
Kenil Vasani
As Iron Fist points out,
RSS
is a set (which aren’t subscriptable), although it looks as though you’re trying to use it as a dictionary. Based on the default value you use forget_news
, I’m hazarding a guess that you want something like this: