Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix AttributeError #15738

Merged
merged 1 commit into from
Jun 8, 2024
Merged

Conversation

JLipnerPitt
Copy link
Contributor

@JLipnerPitt JLipnerPitt commented May 8, 2024

##Description
Fixed an error (AttributeError: 'str' object has no attribute 'decode') coming from line 792 in images.py when trying to upscale certain images. I'm unsure why certain images didn't need to be decoded.

I changed geninfo = items["comment"].decode('utf8', errors="ignore") on line 792 to

    if isinstance(items["comment"], bytes):
        geninfo = items["comment"].decode('utf8', errors="ignore")
    else:
        geninfo = items["comment"]

This resolved the above error. I reattempted upscaling the directory that originally gave me this error and all the images were successfully upscaled with no further issues. I might have found the reason for this error. I ran some of the images that were causing it through metadata2go.com and noticed they all shared a similar formatted comment:

    b'Paint Tool -SAI- JPEG Encoder v1.00\x00'
    b'File written by Adobe Photoshop\xa8 5.2\x00'

I believe that the original code assumed the metadata would always be in bytes of data, which is then decoded into a string. For whatever reason, some of the images had metadata that was already a string, hence the 'str' object has no attribute 'decode' error. I have no idea what leads to this behavior. I'm assuming it's simply a result of how the metadata is handled originally and what technique is used to encode it. I'm not sure how you can reproduce this on a whim since you won't know this is an issue until you try to upscale an image.

metadata for an image that didn't cause the error:
no error metadata

metadata for an image that caused the error:
error metadata

Screenshots/videos:

Upscale attempt with original code:
image

Upscale attempt with new code:
image

Checklist:

Fixed an error (AttributeError: 'str' object has no attribute 'decode') coming from line 792 in images.py when trying to upscale certain images.
@JLipnerPitt JLipnerPitt changed the base branch from master to dev May 8, 2024 15:07
@JLipnerPitt JLipnerPitt changed the title Add files via upload Fix AttributeError May 9, 2024
@AUTOMATIC1111 AUTOMATIC1111 merged commit c1c4b3f into AUTOMATIC1111:dev Jun 8, 2024
3 of 4 checks passed
@JLipnerPitt JLipnerPitt deleted the JLipnerPitt-patch-1 branch June 8, 2024 08:37
@lawchingman lawchingman mentioned this pull request Oct 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants