title: builtins.AttributeError: 'bytes' object has no attribute 'append' in python twisted
body: <p>I am running a multi-chat server in python Twisted framework
  I got the following error while trying to append the second user to dictionary
  builtins.AttributeError: 'bytes' object has no attribute 'append'</p>
  <p>I am getting above error in this follwing code</p>
  <pre><code>elif command == b&quot;/join&quot;:
       self.factory.groups.get(content, []).append(self)
       #self.join_group(content)
  </code></pre>
  <p>I  also make def join_group() :
  please check that too</p>
  <p>HERE IS FULL Trace Back</p>
  <p>Unhandled Error</p>
  <pre><code>Traceback (most recent call last):
    File &quot;C:\Users\admin\AppData\Local\Programs\Python\Python38-32\lib\site-packages\twisted\python\log.py&quot;, line 103, in callWithLogger
      return callWithContext({&quot;system&quot;: lp}, func, *args, **kw)
    File &quot;C:\Users\admin\AppData\Local\Programs\Python\Python38-32\lib\site-packages\twisted\python\log.py&quot;, line 86, in callWithContext
      return context.call({ILogContext: newCtx}, func, *args, **kw)
    File &quot;C:\Users\admin\AppData\Local\Programs\Python\Python38-32\lib\site-packages\twisted\python\context.py&quot;, line 122, in callWithContext
      return self.currentContext().callWithContext(ctx, func, *args, **kw)
    File &quot;C:\Users\admin\AppData\Local\Programs\Python\Python38-32\lib\site-packages\twisted\python\context.py&quot;, line 85, in callWithContext
  
  &gt; `Blockquote`
  
  return func(*args,**kw)
  --- &lt;exception caught here&gt; ---
    File &quot;C:\Users\admin\AppData\Local\Programs\Python\Python38-32\lib\site-packages\twisted\internet\selectreactor.py&quot;, line 149, in _doReadOrWrite
      why = getattr(selectable, method)()
    File &quot;C:\Users\admin\AppData\Local\Programs\Python\Python38-32\lib\site-packages\twisted\internet\tcp.py&quot;, line 243, in doRead
      return self._dataReceived(data)
    File &quot;C:\Users\admin\AppData\Local\Programs\Python\Python38-32\lib\site-packages\twisted\internet\tcp.py&quot;, line 249, in _dataReceived
      rval = self.protocol.dataReceived(data)
    File &quot;C:\Users\admin\AppData\Local\Programs\Python\Python38-32\lib\site-packages\twisted\protocols\basic.py&quot;, line 572, in dataReceived
      why = self.lineReceived(line)
    File &quot;chatserver.py&quot;, line 44, in lineReceived
      self.factory.groups.get(content, []).append(self)
  builtins.AttributeError: 'bytes' object has no attribute 'append'
  </code></pre>
  <p>Full code link please refer it</p>
  <pre><code>from twisted.internet.protocol import Factory
  from twisted.protocols.basic import LineReceiver
  from twisted.internet import reactor
  from collections import defaultdict
  
  
  class MultiChatProtocol(LineReceiver):
      
      def __init__(self, factory):
          self.factory = factory
          self.name = None
          self.group_name = None
          
  
      def connectionMade(self):
          self.sendLine(b&quot;Welcome to multi char server &quot;)
          self.sendLine(b&quot;&quot;) 
          print(type(self.factory.users))
          print(type(self.factory.groups))
          
  
          
          
          
      def connectionLost(self, reason):
          if self.name in self.factory.users:
              self.broadcastMessage(b&quot;one member has left the channel.&quot;)
              
      def lineReceived(self, line):
          if line == b'':
              self.sendLine(b&quot;write something or type /help for any&quot;)
              return
          print(&quot;line name&quot; , line)
          
          a = line.split()
          if len(a) &gt; 1:
              command = a[0]
              content = a[1]
              if command == b&quot;/cuser&quot;:
                  self.save_REGISTER(content)
              elif command == b&quot;/cgroup&quot;:
                  self.create_Group(content)
              elif command == b&quot;/join&quot;:
                  self.factory.groups.get(content, []).append(self)
                  #self.join_group(content)
          elif line == b&quot;/ulist&quot;:
              self.usercount()
          elif line == b&quot;/glist&quot;:
              self.groupcount()
          elif line == b&quot;/help&quot;:
              self.handle_menu()
          elif line == b&quot;/quite&quot;:
              self.connectionLost()
  
      def join_group(self,args):
          print(&quot;args for join&quot;,args)
          print(&quot;user name for join&quot;,self.name)
          #for elem in self.factory.groups:
           #   if args == elem:
            #      elf.factory.groups[args].append(self.name)
          
          d = {}
          y = self.name
          d.setdefault(args, []).append(y)
          print(&quot;groups list of d &quot;, d)
          self.factory.groups = d
          print(&quot;groups list&quot;, self.factory.groups)
      
  
      def save_REGISTER(self,name):
          if name in self.factory.users:
              self.transport.write(b&quot;Name taken, please choose another.&quot;)
              return
          self.sendLine(b&quot;Welcome, %s!&quot; % (name,))
          self.broadcastMessage(b&quot;%s has joined the channel.&quot; % (name,))
          self.name = name
          self.factory.users[name] = self
          print(&quot;users list&quot;,self.factory.users)
          
         
      def create_Group(self,name):
          self.sendLine(b&quot;Enter group name? :&quot;)
          self.save_Group(name)
  
      def create_Group(self,name):
          print(&quot;group_name&quot;, name)
          print(self.name)
          if name in self.factory.groups:
              self.transport.write(b&quot;Name taken, please choose another.&quot;)
              return
          if self.name in self.factory.users:
              self.sendLine(b&quot;%s group created successfully&quot; % (name,))
              self.group_name = name
              self.factory.groups[name] = self
              #self.factory.groups[name] = self.name
              print(&quot;groups list&quot;,  self.factory.groups)
              
          else:
              self.sendLine(b&quot;you are not register with system sorry&quot;)
              
    
  
      def handle_menu(self):
          self.sendLine(b&quot;&quot;)
          self.sendLine(b&quot; please select Following MENU command:&quot;)
          self.sendLine(b&quot;1) For register your name type : /cuser yourname&quot;)
          self.sendLine(b&quot;2) For create group type : /cgroup groupname&quot;)
          self.sendLine(b&quot;3) For Joined group type : /join groupname&quot;)
          self.sendLine(b&quot;4) For see list Of group type : /glist&quot;)
          self.sendLine(b&quot;5) For exit type : /quite&quot;)
          
          
  
      def handle_CHAT(self, message):    
          message = b&quot;&lt;%s&gt; %s&quot; % (self.name,message)
          self.broadcastMessage(message)
  
      def broadcastMessage(self, message):
          for name, protocol in self.factory.users.items():
              if protocol != self:
                  protocol.sendLine(message)
  
      def usercount(self):
  
          user_count = len(self.factory.users)                                               
          single_or_plural = b'is' if user_count == 1 else b'are'                                                    
          person_or_people = b'person' if user_count == 1 else b'people'                                             
          self.sendLine(b&quot;There %s %i  %s connected:&quot; % (single_or_plural, user_count, person_or_people, ) )                    
  
          for client in self.factory.users:                                              
              if client is not self:                                                       
                  self.sendLine(client)                                               
          self.sendLine(b&quot;&quot;)
  
      def groupcount(self):
          group_count = len(self.factory.groups)                                               
          single_or_plural = b'is' if group_count == 1 else b'are'                                                    
          person_or_people = b'group' if group_count == 1 else b'groups'                                             
          self.sendLine(b&quot;There %s  %i following %s we have :&quot; % (single_or_plural, group_count, person_or_people, ) )                    
  
          for group in self.factory.groups:                                              
              if group is not self:                                                       
                  self.sendLine(group)                                               
          self.sendLine(b&quot;&quot;)
          self.sendLine(b&quot;joined above groups by command /join groupname&quot;)
          
  
  class ChatFactory(Factory):
      def __init__(self):
          self.users = {}
          self.groups = {}
          
      def buildProtocol(self, addr):
          return MultiChatProtocol(self)
      
  reactor.listenTCP(8000, ChatFactory())
  print (&quot;Chat Server Started&quot;) 
  reactor.run()
  </code></pre>
  <p>thank you.</p>