# Buggy code
def WriteInfo(self, filename):
    info = None
    try:
        # Issue #421 ensure subdir exists.
        PixivHelper.makeSubdirs(filename)

        info = codecs.open(filename, "wb", encoding="utf-8")
    except IOError:
        info = codecs.open(str(self.imageId) + ".txt", "wb", encoding="utf-8")
        PixivHelper.GetLogger().exception(
            "Error when saving image info: {0}, file is saved to: {1}.txt".format(
                filename, self.imageId
            )
        )

    info.write("ArtistID      = {0}\r\n".format(self.parent.artistId))
    info.write("ArtistName    = {0}\r\n".format(self.parent.artistName))

    info.write("ImageID       = {0}\r\n".format(self.imageId))
    info.write("Title         = {0}\r\n".format(self.imageTitle))
    info.write("Caption       = {0}\r\n".format(self.body_text))
    # info.write(u"Tags          = " + ", ".join(self.imageTags) + "\r\n")
    if self.is_restricted:
        info.write("Image Mode    = {0}, Restricted\r\n".format(self.type))
    else:
        info.write("Image Mode    = {0}\r\n".format(self.type))
    info.write("Pages         = {0}\r\n".format(self.imageCount))
    info.write("Date          = {0}\r\n".format(self.worksDate))
    # info.write(u"Resolution    = " + self.worksResolution + "\r\n")
    # info.write(u"Tools         = " + self.worksTools + "\r\n")
    info.write("Like Count    = {0}\r\n".format(self.likeCount))
    info.write(
        "Link          = https://www.pixiv.net/fanbox/creator/{0}/post/{1}\r\n".format(
            self.parent.artistId, self.imageId
        )
    )
    # info.write("Ugoira Data   = " + str(self.ugoira_data) + "\r\n")
    if len(self.embeddedFiles) > 0:
        info.write("Urls          =\r\n")
        for link in self.embeddedFiles:
            info.write(" - {0}\r\n".format(link))
    info.close()


# Traceback (RuntimeError)
Traceback (most recent call last):
File "PixivUtil2.py", line 270, in download_image
File "zipfile.pyc", line 901, in testzip
File "zipfile.pyc", line 993, in open
RuntimeError: File cover.jpg is encrypted, password required for extraction
Error at download_image(): (<type 'exceptions.RuntimeError'>, RuntimeError('File cover.jpg is encrypted, password required for extraction',), <traceback object at 0x042BE030>) at [REDACTED link for privacy reasons] (9000)
Traceback (most recent call last):
File "PixivUtil2.py", line 2369, in main
File "PixivUtil2.py", line 2126, in main_loop
File "PixivUtil2.py", line 1876, in menu_fanbox_download_supported_artist
File "PixivUtil2.py", line 1925, in processFanboxArtist
File "PixivUtil2.py", line 1978, in processFanboxImages
File "PixivUtil2.py", line 270, in download_image
File "zipfile.pyc", line 901, in testzip
File "zipfile.pyc", line 993, in open
RuntimeError: File cover.jpg is encrypted, password required for extraction
press enter to exit.

# Fixed code
def WriteInfo(self, filename):
    info = None
    try:
        # Issue #421 ensure subdir exists.
        PixivHelper.makeSubdirs(filename)

        info = codecs.open(filename, "wb", encoding="utf-8")
    except IOError:
        info = codecs.open(str(self.imageId) + ".txt", "wb", encoding="utf-8")
        PixivHelper.GetLogger().exception(
            "Error when saving image info: %s, file is saved to: %s.txt",
            filename,
            self.imageId,
        )

    info.write("ArtistID      = {0}\r\n".format(self.parent.artistId))
    info.write("ArtistName    = {0}\r\n".format(self.parent.artistName))

    info.write("ImageID       = {0}\r\n".format(self.imageId))
    info.write("Title         = {0}\r\n".format(self.imageTitle))
    info.write("Caption       = {0}\r\n".format(self.body_text))
    # info.write(u"Tags          = " + ", ".join(self.imageTags) + "\r\n")
    if self.is_restricted:
        info.write("Image Mode    = {0}, Restricted\r\n".format(self.type))
    else:
        info.write("Image Mode    = {0}\r\n".format(self.type))
    info.write("Pages         = {0}\r\n".format(self.imageCount))
    info.write("Date          = {0}\r\n".format(self.worksDate))
    # info.write(u"Resolution    = " + self.worksResolution + "\r\n")
    # info.write(u"Tools         = " + self.worksTools + "\r\n")
    info.write("Like Count    = {0}\r\n".format(self.likeCount))
    info.write(
        "Link          = https://www.pixiv.net/fanbox/creator/{0}/post/{1}\r\n".format(
            self.parent.artistId, self.imageId
        )
    )
    # info.write("Ugoira Data   = " + str(self.ugoira_data) + "\r\n")
    if len(self.embeddedFiles) > 0:
        info.write("Urls          =\r\n")
        for link in self.embeddedFiles:
            info.write(" - {0}\r\n".format(link))
    info.close()