Skip to content

Commit

Permalink
Merge pull request #252 from praw-dev/fix-xml-parsing
Browse files Browse the repository at this point in the history
Fix xml parsing on error
  • Loading branch information
LilSpazJoekp committed Sep 10, 2023
2 parents 06c5cde + 4354bee commit 5b64098
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions asyncpraw/models/reddit/subreddit.py
Original file line number Diff line number Diff line change
Expand Up @@ -931,9 +931,9 @@ async def _fetch_data(self) -> dict:
def _fetch_info(self):
return "subreddit_about", {"subreddit": self}, None

def _parse_xml_response(self, response: ClientResponse):
async def _parse_xml_response(self, response: ClientResponse):
"""Parse the XML from a response and raise any errors found."""
xml = response.text
xml = await response.text()
root = XML(xml)
tags = [element.tag for element in root]
if tags[:4] == ["Code", "Message", "ProposedSize", "MaxSizeAllowed"]:
Expand Down Expand Up @@ -1063,7 +1063,7 @@ async def _upload_media(

response = await self._read_and_post_media(media_path, upload_url, upload_data)
if not response.status == 201:
self._parse_xml_response(response)
await self._parse_xml_response(response)
try:
response.raise_for_status()
except HttpProcessingError:
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/models/reddit/test_subreddit.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import socket
import sys
from asyncio import TimeoutError
from unittest.mock import MagicMock
from unittest.mock import AsyncMock, MagicMock

import pytest
from aiohttp import ClientResponse
Expand Down Expand Up @@ -1611,7 +1611,7 @@ async def patch_request(url, *args, **kwargs):
"""Patch requests to return mock data on specific url."""
if "https://reddit-uploaded-media.s3-accelerate.amazonaws.com" in url:
response = ClientResponse
response.text = mock_data
response.text = AsyncMock(return_value=mock_data)
response.status = 400
return response
return await _post(url, *args, **kwargs)
Expand Down

0 comments on commit 5b64098

Please sign in to comment.