我正在使用Feedgen生成RSS提要,但如何设置编码以显示法语字符
app.py
# Flask package
# pip install flask
from flask import make_response
from flask import Flask, Response
# Other Python external packages
# pip install feedgen
from feedgen.feed import FeedGenerator
app = Flask(__name__, static_url_path='')
def get_feed_object():
fg = FeedGenerator()
fg.title("STO Bug")
fg.description(
"STO question"
)
fg.link(href="https://sto.com")
return fg
@app.route("/", methods=("GET",))
def rss():
fg = get_feed_object()
downloads = [
{
'Survey': "Enquête sociale générale, cycle 29",
},
{
'Survey': 'Enquête sociale générale, cycle 30',
}
]
for survey in downloads[:20]:
fe = fg.add_entry()
fe.title(
survey["Survey"]
)
response = make_response(fg.rss_str(encoding='UTF-8'))
response.headers.set("Content-Type", "application/rss+xml")
return response
if __name__ == "__main__":
app.run(host="0.0.0.0", port=5000, debug=True)
我需要在response.header中设置编码
相关问题 更多 >
编程相关推荐