python - python - 如何使用feedgen在RSS提要中显示法语字符编码
问题描述
我正在使用Feedgen生成 RSS 提要,但如何设置编码以显示法语字符。
应用程序.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 中设置编码
response.headers.set("Content-Type", "application/rss+xml; charset=utf-8")
推荐阅读
- c# - 为什么我的光线投射命中点预期输出与实际输出不同?
- sql - 具有 INT 和 NVARCHAR 数据类型的多列的 SQL Pivot
- entity-framework - 在实体框架模型中包含只读列
- visual-studio-code - VSCode 扩展:打开文件时添加文档元数据
- python - 为什么从 HTML 到 CSS 的 href 不能在 Django 中正常工作?
- json - Swift - 具有通用 Dictionary var 的可编码结构?
- javascript - 在 setInterval 中播放声音
- sql - SQL如何获得介于特定左右值之间的值的一部分
- signalr - Azure SignalR 服务尚未连接,请稍后再试
- r - ggplot2:即使没有图例,也要在旁边留一个空格