Skip to content

Commit

Permalink
Decode content using the encoding specified in the response
Browse files Browse the repository at this point in the history
  • Loading branch information
SamTheisens authored and lechat committed Aug 19, 2023
1 parent 525cf02 commit 284fa60
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions jenkinsapi/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,14 +477,15 @@ def get_console(self) -> str:
Return the current state of the text console.
"""
url: str = "%s/consoleText" % self.baseurl
content: Any = self.job.jenkins.requester.get_url(url).content
resp = self.job.jenkins.requester.get_url(url)
content: Any = resp.content
# This check was made for Python 3.x
# In this version content is a bytes string
# By contract this function must return string
if isinstance(content, str):
return content
elif isinstance(content, bytes):
return content.decode("ISO-8859-1")
return content.decode(resp.encoding or "ISO-8859-1")
else:
raise JenkinsAPIException("Unknown content type for console")

Expand All @@ -504,7 +505,7 @@ def stream_logs(self, interval=0) -> Iterator[str]:
if isinstance(content, str):
yield content
elif isinstance(content, bytes):
yield content.decode("ISO-8859-1")
yield content.decode(resp.encoding or "ISO-8859-1")
else:
raise JenkinsAPIException(
"Unknown content type for console"
Expand Down

0 comments on commit 284fa60

Please sign in to comment.