[Jira] Fix get_attachment_content() return the content as bytes
instead of str
#1433
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem / Observation
Using the method
get_attachment_content()
returns astr
of the content, which corrupts the actual content bytes due to encoding issues.Usage example (problem showcase)
Assuming, there's a PNG image attached to a ticket, in my use case I want to download the PNG image.
This leads to a runtime exception:
a bytes-like object is required, not 'str'
IF I try to use text file mode
open("content.png", 'w')
then the content is broken due to utf-8 encoding, which is obviously not required, but used due to the fact the content object type isstr
.Fix
Don't convert an attachment content into a string, e.g. using
self.get(url, not_json_response=True)
Impact
Context