Skip to content

Commit

Permalink
fix: raise for requests status error
Browse files Browse the repository at this point in the history
  • Loading branch information
p0n1 committed Nov 11, 2023
1 parent c2b56fe commit 9ab7db0
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions epub_to_audiobook.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ def auto_renew_access_token(self) -> str:
def get_access_token(self) -> str:
for retry in range(MAX_RETRIES):
try:
logger.info("Getting new access token")
response = requests.post(self.TOKEN_URL, headers=self.TOKEN_HEADERS)
response.raise_for_status() # Will raise HTTPError for 4XX or 5XX status
access_token = str(response.text)
logger.info("Got new access token")
return access_token
Expand Down Expand Up @@ -176,9 +178,12 @@ def text_to_speech(
"User-Agent": "Python",
}
try:
logger.info("Sending request to Azure TTS, data length: " + str(len(ssml)))
response = requests.post(
self.TTS_URL, headers=headers, data=ssml.encode("utf-8")
)
response.raise_for_status() # Will raise HTTPError for 4XX or 5XX status
logger.info("Got response from Azure TTS, response length: " + str(len(response.content)))
audio_segments.append(io.BytesIO(response.content))
break
except requests.exceptions.RequestException as e:
Expand Down

0 comments on commit 9ab7db0

Please sign in to comment.