我創建了兩個函式 get_feeds_ui() 和 get_feeds_ol() 來嘗試從 rss 提要 URLS 中獲取資料。第一個函式回傳資料,但第二個函式不是。任何人都知道缺少什么或我需要做什么?我是 python 新手。
from flask import Flask ,jsonify
from flask_cors import CORS, cross_origin
app = Flask(__name__)
CORS(app, resources={r"/api/*":{"origins":"*"}})
app.config['CORS HEADERS'] = 'Content-Type'
URLS =['https://status.ui.com/history.rss',
'http://status.us.onelogin.com/pages/538511e2ce5cb97537000144/rss']
@app.route("/feed", methods=['POST','GET'])
@cross_origin()
def get_feeds_ui():
feed = feedparser.parse(URLS[0])
first_article = feed['entries'][0]
return jsonify(title=first_article.title,
link=first_article.link,
updated=first_article.updated)
def get_feeds_ol():
feed = feedparser.parse(URLS[1])
first_article = feed['entries'][0]
return jsonify(title=first_article.title,
link=first_article.link,
updated=first_article.updated)
if __name__ == '__main__':
app.run(debug=True)
uj5u.com熱心網友回復:
您沒有在第二個函式中指定 URL。您需要在用作 api 的每個函式上指定 URL。
@app.route("/feed_ol", methods=['POST','GET'])
def get_feeds_ol():
feed = feedparser.parse(URLS[1])
first_article = feed['entries'][0]
return jsonify(title=first_article.title,
link=first_article.link,
updated=first_article.updated)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/487544.html
上一篇:AWK變數和函式語法
