Click here to Skip to main content
15,844,387 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
My Flask code look like

Python
  <pre>
# A very simple Flask Hello World app for you to get started with...

from flask import Flask,Response

from flask import request
from bs4 import BeautifulSoup
import json
app = Flask(__name__)

if '_name_' == '_main_':
    app.run(threaded=True)

@app.route('/')
def home():
    return 'News API is UP!<br><br> itis hsh hfslab s,djhdsbf s,ajsbf ajsdfbs '
@app.route('/news' , methods=['GET'])
def handlle_request():
    url = 'https://www.indiatoday.in/rss/home'
    r = request.args.get(url)
    soup = BeautifulSoup(r.content, 'xml')
    items = soup.findAll('item')
    newList = []
    for item in items:
        title = item.find("title").text.strip()
        url = item.find("link").text.strip()

        new = {
           "title":title,
           "url":url
         }

        newList.append(new)

    y= json.dumps(newList, indent=2)
    return  Response(y , mimetype="application/json")



What I have tried:

what error I got
 return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
  File "/home/jonsnow99/mysite/flask_app.py", line 15, in handlle_request
    r = request.get(url)
AttributeError: 'Request' object has no attribute 'get'
Posted
Updated 2-Sep-22 6:51am

1 solution

You do not show which is line 15, but I cannot see a line like:
Python
r = request.get(url)

However, I suspect what you need is:
Python
r = request.args.get(url)

as you have in the above code. See also 3. Incoming Request Data — Flask API[^].
 
Share this answer
 
Comments
jon773599 2-Sep-22 11:53am    
i already add request.args.get(url)
still getting error
Richard MacCutchan 2-Sep-22 12:07pm    
Please show the exact code you are using, and the exact error message.
jon773599 2-Sep-22 12:09pm    
now i am getting new error
soup = BeautifulSoup(r.content, 'xml')
AttributeError: 'NoneType' object has no attribute 'content'
Richard MacCutchan 2-Sep-22 12:16pm    
Because r is a "NoneType", that is to say it has not been set to a valid reference. So look at the line where you set r to some value and try to find out why it failed.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900