Sign Up

Have an account? Sign In Now

Sign In

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

Sorry, you do not have a permission to ask a question, You must login to ask question.

Forgot Password?

Need An Account, Sign Up Here
Sign InSign Up

ErrorCorner

ErrorCorner Logo ErrorCorner Logo

ErrorCorner Navigation

  • Home
  • Contact Us
  • About Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Contact Us
  • About Us
Home/ Questions/Q 613
Next
Answered
Kenil Vasani
Kenil Vasani

Kenil Vasani

  • 646 Questions
  • 567 Answers
  • 77 Best Answers
  • 26 Points
View Profile
  • 3
Kenil Vasani
Asked: December 14, 20202020-12-14T21:07:13+00:00 2020-12-14T21:07:13+00:00In: Python

TypeError: ‘set’ object is not subscriptable

  • 3

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

flaskpython
  • 1 1 Answer
  • 10 Views
  • 0 Followers
  • 0
Answer
Share
  • Facebook

    1 Answer

    • Voted
    1. Kenil Vasani

      Kenil Vasani

      • 646 Questions
      • 567 Answers
      • 77 Best Answers
      • 26 Points
      View Profile
      Best Answer
      Kenil Vasani
      2020-12-14T21:02:23+00:00Added an answer on December 14, 2020 at 9:02 pm

      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 for get_news, I’m hazarding a guess that you want something like this:

      RSS = {"bbc": "http://feeds.bbci.co.uk/news/rss.xml",
             "iol": "http://rss.iol.io/iol/news",
             "fox": "http://feeds.foxnews.com/foxnews/latest",
             "cnn": "http://rss.cnn.com/rss/edition.rss"}
      
      • 0
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp

    You must login to add an answer.

    Forgot Password?

    Sidebar

    Ask A Question
    • Popular
    • Kenil Vasani

      SyntaxError: invalid syntax to repo init in the AOSP code

      • 5 Answers
    • Kenil Vasani

      xlrd.biffh.XLRDError: Excel xlsx file; not supported

      • 3 Answers
    • Kenil Vasani

      Homebrew fails on MacOS Big Sur

      • 3 Answers
    • Kenil Vasani

      runtimeError: package fails to pass a sanity check for numpy ...

      • 3 Answers
    • Kenil Vasani

      FATAL EXCEPTION: Firebase-Messaging-Intent-Handle — java.lang.NoClassDefFoundError

      • 2 Answers

    Explore

    • Most Answered
    • Most Visited
    • Most Voted
    • Random

    © 2020-2021 ErrorCorner. All Rights Reserved
    by ErrorCorner.com