# Buggy code
def _save(self):
    """
    Save config into the associated .ini file
    """
    # See Issue 1086 and 1242 for background on why this
    # method contains all the exception handling.
    fname = self.filename()

    def _write_file(fname):
        if PY2:
            # Python 2
            with codecs.open(fname, "w", encoding="utf-8") as configfile:
                self._write(configfile)
        else:
            # Python 3
            with open(fname, "w", encoding="utf-8") as configfile:
                self.write(configfile)

    try:  # the "easy" way
        _write_file(fname)
    except IOError:
        try:  # the "delete and sleep" way
            if osp.isfile(fname):
                os.remove(fname)
            time.sleep(0.05)
            _write_file(fname)
        except Exception as e:
            print("Failed to write user configuration file.")  # spyder: test-skip
            print("Please submit a bug report.")  # spyder: test-skip
            raise (e)


# Traceback (OSError)
File "C:\Anaconda3\lib\site-packages\spyder\config\user.py", line 110, in _save
_write_file(fname)
File "C:\Anaconda3\lib\site-packages\spyder\config\user.py", line 106, in _write_file
with open(fname, 'w', encoding='utf-8') as configfile:
OSError: [Errno 22] Invalid argument: 'C:\\Users\\Administrator\\.spyder-py3\\spyder.ini'

Traceback (most recent call last):
File "C:\Anaconda3\lib\site-packages\spyder\plugins\__init__.py", line 440, in set_option
CONF.set(self.CONF_SECTION, str(option), value)
File "C:\Anaconda3\lib\site-packages\spyder\config\user.py", line 445, in set
self._save()
File "C:\Anaconda3\lib\site-packages\spyder\config\user.py", line 120, in _save
raise(e)
File "C:\Anaconda3\lib\site-packages\spyder\config\user.py", line 114, in _save
os.remove(fname)
PermissionError: [WinError 5] Access is denied: 'C:\\Users\\Administrator\\.spyder-py3\\spyder.ini'
WARNING:spyder.widgets.github.backend:failed to send bug report on github. response={'code': 401, 'json': {'message': 'Bad credentials', 'documentation_url': 'https://developer.github.com/v3'}}
WARNING:spyder.widgets.github.backend:failed to send bug report on github. response={'code': 401, 'json': {'message': 'Bad credentials', 'documentation_url': 'https://developer.github.com/v3'}}

# Fixed code
def _save(self):
    """
    Save config into the associated .ini file
    """
    # See Issue 1086 and 1242 for background on why this
    # method contains all the exception handling.
    fname = self.filename()

    def _write_file(fname):
        if PY2:
            # Python 2
            with codecs.open(fname, "w", encoding="utf-8") as configfile:
                self._write(configfile)
        else:
            # Python 3
            with open(fname, "w", encoding="utf-8") as configfile:
                self.write(configfile)

    try:  # the "easy" way
        _write_file(fname)
    except EnvironmentError:
        try:  # the "delete and sleep" way
            if osp.isfile(fname):
                os.remove(fname)
            time.sleep(0.05)
            _write_file(fname)
        except Exception as e:
            print(
                "Failed to write user configuration file to disk, with "
                "the exception shown below"
            )  # spyder: test-skip
            print(e)  # spyder: test-skip