Skip to content

Commit 55748e0

Browse files
committed
fix: handle content being string or http Response in _raise_for_status
1 parent b5ac8bf commit 55748e0

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

deepl/translator.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -548,20 +548,23 @@ def _api_call(
548548

549549
json = None
550550
if isinstance(content, str):
551+
content_str = content
551552
try:
552553
json = json_module.loads(content)
553554
except json_module.JSONDecodeError:
554555
pass
556+
else:
557+
content_str = content.text
555558

556559
util.log_info("DeepL API response", url=url, status_code=status_code)
557-
util.log_debug("Response details", content=content)
560+
util.log_debug("Response details", content=content_str)
558561

559562
return status_code, content, json
560563

561564
def _raise_for_status(
562565
self,
563566
status_code: int,
564-
content: str,
567+
content: Union[str, requests.Response],
565568
json: Optional[dict],
566569
glossary: bool = False,
567570
downloading_document: bool = False,
@@ -624,9 +627,10 @@ def _raise_for_status(
624627
if status_code in http.client.responses
625628
else "Unknown"
626629
)
630+
content_str = content if isinstance(content, str) else content.text
627631
raise DeepLException(
628632
f"Unexpected status code: {status_code} {status_name}, "
629-
f"content: {content}.",
633+
f"content: {content_str}.",
630634
should_retry=False,
631635
http_status_code=status_code,
632636
)

0 commit comments

Comments
 (0)