Python typeerror unbound emit method should be called with streamhandler instance as fistr argument (filehandler instance was got instead)

python module paramiko throws weird exception as shown in tile. And finally I find the position that actually happens, which is in the logging module . when I set a breakpoint on a line in Eclipse with pydev and put the lines below in the expression view , the evaluated value confused me. I wonder in which case an exception can occur, although this is not possible from my point of view.

self.__class__ # <class 'logging.FileHandler'>
isinstance(self, FileHandler)  # False
isinstance(self, StreamHandler) # False

      

fix FileHandler method:

def emit(self, record):
    """
    Emit a record.

    If the stream was not opened because 'delay' was specified in the
    constructor, open it before calling the superclass emit.
    """
    if self.stream is None:
        self.stream = self._open()
    StreamHandler.emit(self, record)

      

+3


source to share


1 answer


Finally fixed this. Reloading the module logging

caused this issue.



+2


source







All Articles