# Buggy code
def __init__(self, channel, ttyBaudrate=115200, timeout=1, bitrate=None, **kwargs):
    """
    :param str channel:
        port of underlying serial or usb device (e.g. /dev/ttyUSB0, COM8, ...)
        Must not be empty.
    :param int ttyBaudrate:
        baudrate of underlying serial or usb device
    :param int bitrate:
        Bitrate in bit/s
    :param float poll_interval:
        Poll interval in seconds when reading messages
    :param float timeout:
        timeout in seconds when reading message
    """

    if not channel:  # if None or empty
        raise TypeError("Must specify a serial port.")

    if "@" in channel:
        (channel, ttyBaudrate) = channel.split("@")

    self.serialPortOrig = serial.Serial(channel, baudrate=ttyBaudrate, timeout=timeout)
    self.serialPort = io.TextIOWrapper(
        io.BufferedRWPair(self.serialPortOrig, self.serialPortOrig, 1),
        newline="\r",
        line_buffering=True,
    )

    time.sleep(self._SLEEP_AFTER_SERIAL_OPEN)

    if bitrate is not None:
        self.close()
        if bitrate in self._BITRATES:
            self.write(self._BITRATES[bitrate])
        else:
            raise ValueError(
                "Invalid bitrate, choose one of " + (", ".join(self._BITRATES)) + "."
            )

    self.open()

    super(slcanBus, self).__init__(
        channel, ttyBaudrate=115200, timeout=1, bitrate=None, **kwargs
    )


# Traceback (AttributeError)
DEBUG:can:loaded can config: {'interface': 'slcan', 'channel': '/dev/ttyUSB0@115200'}
Traceback (most recent call last):
File "encoder-test.py", line 19, in <module>
network.connect(channel='/dev/ttyUSB0@115200', bustype='slcan')
File "/usr/local/lib/python3.5/dist-packages/canopen/network.py", line 100, in connect
self.bus = can.interface.Bus(*args, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/can/interface.py", line 120, in __new__
return cls(channel, *args, **config)
File "/usr/local/lib/python3.5/dist-packages/can/interfaces/slcan.py", line 81, in __init__
self.open()
File "/usr/local/lib/python3.5/dist-packages/can/interfaces/slcan.py", line 93, in open
self.write('O')
File "/usr/local/lib/python3.5/dist-packages/can/interfaces/slcan.py", line 89, in write
self.serialPort.write(string.decode())
AttributeError: 'str' object has no attribute 'decode'

# Fixed code
def __init__(self, channel, ttyBaudrate=115200, timeout=1, bitrate=None, **kwargs):
    """
    :param str channel:
        port of underlying serial or usb device (e.g. /dev/ttyUSB0, COM8, ...)
        Must not be empty.
    :param int ttyBaudrate:
        baudrate of underlying serial or usb device
    :param int bitrate:
        Bitrate in bit/s
    :param float poll_interval:
        Poll interval in seconds when reading messages
    :param float timeout:
        timeout in seconds when reading message
    """

    if not channel:  # if None or empty
        raise TypeError("Must specify a serial port.")

    if "@" in channel:
        (channel, ttyBaudrate) = channel.split("@")

    self.serialPortOrig = serial.Serial(channel, baudrate=ttyBaudrate, timeout=timeout)

    time.sleep(self._SLEEP_AFTER_SERIAL_OPEN)

    if bitrate is not None:
        self.close()
        if bitrate in self._BITRATES:
            self.write(self._BITRATES[bitrate])
        else:
            raise ValueError(
                "Invalid bitrate, choose one of " + (", ".join(self._BITRATES)) + "."
            )

    self.open()

    super(slcanBus, self).__init__(
        channel, ttyBaudrate=115200, timeout=1, bitrate=None, **kwargs
    )