Skip to content

Commit

Permalink
Pass raw data to feedparser. Fixes #59
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Jan 30, 2025
1 parent 68e5a84 commit 72d0809
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions rss/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,15 +257,9 @@ def _parse_json_entry(cls, feed_id: int, entry: dict[str, Any]) -> Entry:
async def _parse_rss(
cls, feed: Feed, resp: aiohttp.ClientResponse
) -> tuple[Feed, list[Entry]]:
try:
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]
content = await resp.read()
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 not isinstance(parsed_data.bozo_exception, feedparser.ThingsNobodyCaresAboutButMe):
raise parsed_data.bozo_exception
Expand Down

0 comments on commit 72d0809

Please sign in to comment.