# Buggy code
def dump_html(filename, html_text):
    isDumpEnabled = True
    filename = sanitize_filename(filename)
    if _config is not None:
        isDumpEnabled = _config.enableDump
        if _config.enableDump:
            if len(_config.skipDumpFilter) > 0:
                matchResult = re.findall(_config.skipDumpFilter, filename)
                if matchResult is not None and len(matchResult) > 0:
                    isDumpEnabled = False

    if html_text is not None and len(html_text) == 0:
        print_and_log("info", "Empty Html.")
        return ""

    if isDumpEnabled:
        try:
            dump = open(filename, "wb")
            dump.write(str(html_text))
            dump.close()
            return filename
        except IOError as ex:
            print_and_log("error", str(ex))
        print_and_log("info", "Dump File created: {0}".format(filename))
    else:
        print_and_log("info", "Dump not enabled.")
    return ""


# Traceback (ValueError)
Input: 1
Member ids: 668238
Start Page (default=1):
End Page (default=0, 0 for no limit):
Member IDs: [668238]
Processing Member Id: 668238
Reading /mnt/c/PixivUtil2/config.ini ...
done.
Page  1
Member Url: https://www.pixiv.net/ajax/user/668238/profile/all
Member ID (668238): 1002 This user account has been suspended., hasDumpPage=Y
Traceback (most recent call last):
File "/mnt/c/PixivUtil2/PixivBrowserFactory.py", line 480, in getMemberInfoWhitecube
info_ajax_str = self.open_with_retry(url_ajax).read()
File "/mnt/c/PixivUtil2/PixivBrowserFactory.py", line 147, in open_with_retry
return self.open(url, data, timeout)
File "/home/whinette/.local/lib/python3.7/site-packages/mechanize/_mechanize.py", line 253, in open
return self._mech_open(url_or_request, data, timeout=timeout)
File "/home/whinette/.local/lib/python3.7/site-packages/mechanize/_mechanize.py", line 309, in _mech_open
raise response
mechanize._response.get_seek_wrapper_class.<locals>.httperror_seek_wrapper: HTTP Error 403: Forbidden

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "PixivUtil2.py", line 443, in process_member
(artist, list_page) = PixivBrowserFactory.getBrowser().getMemberPage(member_id, page, bookmark, tags)
File "/mnt/c/PixivUtil2/PixivBrowserFactory.py", line 557, in getMemberPage
self.getMemberInfoWhitecube(member_id, artist, bookmark)
File "/mnt/c/PixivUtil2/PixivBrowserFactory.py", line 506, in getMemberInfoWhitecube
msg, errorCode=PixivException.USER_ID_SUSPENDED, htmlPage=errorMessage)
PixivException.PixivException: 1002 This user account has been suspended., hasDumpPage=Y

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "PixivUtil2.py", line 454, in process_member
PixivHelper.dump_html("Dump for " + str(member_id) + " Error Code " + str(ex.errorCode) + ".html", list_page)
File "/mnt/c/PixivUtil2/PixivHelper.py", line 422, in dump_html
dump = open(filename, 'wb', encoding="utf-8")
ValueError: binary mode doesn't take an encoding argument
Error at process_member(): (<class 'ValueError'>, ValueError("binary mode doesn't take an encoding argument"), <traceback object at 0x7f162a5ad7d0>)
Cannot dump page for member_id: 668238
Traceback (most recent call last):
File "/mnt/c/PixivUtil2/PixivBrowserFactory.py", line 480, in getMemberInfoWhitecube
info_ajax_str = self.open_with_retry(url_ajax).read()
File "/mnt/c/PixivUtil2/PixivBrowserFactory.py", line 147, in open_with_retry
return self.open(url, data, timeout)
File "/home/whinette/.local/lib/python3.7/site-packages/mechanize/_mechanize.py", line 253, in open
return self._mech_open(url_or_request, data, timeout=timeout)
File "/home/whinette/.local/lib/python3.7/site-packages/mechanize/_mechanize.py", line 309, in _mech_open
raise response
mechanize._response.get_seek_wrapper_class.<locals>.httperror_seek_wrapper: HTTP Error 403: Forbidden

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "PixivUtil2.py", line 443, in process_member
(artist, list_page) = PixivBrowserFactory.getBrowser().getMemberPage(member_id, page, bookmark, tags)
File "/mnt/c/PixivUtil2/PixivBrowserFactory.py", line 557, in getMemberPage
self.getMemberInfoWhitecube(member_id, artist, bookmark)
File "/mnt/c/PixivUtil2/PixivBrowserFactory.py", line 506, in getMemberInfoWhitecube
msg, errorCode=PixivException.USER_ID_SUSPENDED, htmlPage=errorMessage)
PixivException.PixivException: 1002 This user account has been suspended., hasDumpPage=Y

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "PixivUtil2.py", line 2404, in main
np_is_valid, op_is_valid, selection = main_loop(ewd, op_is_valid, selection, np_is_valid, args)
File "PixivUtil2.py", line 2114, in main_loop
menu_download_by_member_id(op_is_valid, args)
File "PixivUtil2.py", line 1528, in menu_download_by_member_id
process_member(member_id, page=page, end_page=end_page, title_prefix=prefix)
File "PixivUtil2.py", line 454, in process_member
PixivHelper.dump_html("Dump for " + str(member_id) + " Error Code " + str(ex.errorCode) + ".html", list_page)
File "/mnt/c/PixivUtil2/PixivHelper.py", line 422, in dump_html
dump = open(filename, 'wb', encoding="utf-8")
ValueError: binary mode doesn't take an encoding argument
press enter to exit.

# Fixed code
def dump_html(filename, html_text):
    isDumpEnabled = True
    filename = sanitize_filename(filename)
    if _config is not None:
        isDumpEnabled = _config.enableDump
        if _config.enableDump:
            if len(_config.skipDumpFilter) > 0:
                matchResult = re.findall(_config.skipDumpFilter, filename)
                if matchResult is not None and len(matchResult) > 0:
                    isDumpEnabled = False

    if html_text is not None and len(html_text) == 0:
        print_and_log("info", "Empty Html.")
        return ""

    if isDumpEnabled:
        try:
            dump = open(filename, "wb")
            dump.write(html_text)
            dump.close()
            return filename
        except IOError as ex:
            print_and_log("error", str(ex))
        print_and_log("info", "Dump File created: {0}".format(filename))
    else:
        print_and_log("info", "Dump not enabled.")
    return ""