mirror of
https://github.com/maubot/rss.git
synced 2025-08-12 16:45:55 -04:00
Pass raw data to feedparser. Fixes #59
This commit is contained in:
parent
68e5a84096
commit
72d08096b7
1 changed files with 2 additions and 8 deletions
10
rss/bot.py
10
rss/bot.py
|
@ -257,15 +257,9 @@ class RSSBot(Plugin):
|
||||||
async def _parse_rss(
|
async def _parse_rss(
|
||||||
cls, feed: Feed, resp: aiohttp.ClientResponse
|
cls, feed: Feed, resp: aiohttp.ClientResponse
|
||||||
) -> tuple[Feed, list[Entry]]:
|
) -> tuple[Feed, list[Entry]]:
|
||||||
try:
|
content = await resp.read()
|
||||||
content = await resp.text()
|
|
||||||
except UnicodeDecodeError:
|
|
||||||
try:
|
|
||||||
content = await resp.text(encoding="utf-8", errors="ignore")
|
|
||||||
except UnicodeDecodeError:
|
|
||||||
content = str(await resp.read())[2:-1]
|
|
||||||
headers = {"Content-Location": feed.url, **resp.headers, "Content-Encoding": "identity"}
|
headers = {"Content-Location": feed.url, **resp.headers, "Content-Encoding": "identity"}
|
||||||
parsed_data = feedparser.parse(io.StringIO(content), response_headers=headers)
|
parsed_data = feedparser.parse(io.BytesIO(content), response_headers=headers)
|
||||||
if parsed_data.bozo:
|
if parsed_data.bozo:
|
||||||
if not isinstance(parsed_data.bozo_exception, feedparser.ThingsNobodyCaresAboutButMe):
|
if not isinstance(parsed_data.bozo_exception, feedparser.ThingsNobodyCaresAboutButMe):
|
||||||
raise parsed_data.bozo_exception
|
raise parsed_data.bozo_exception
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue