title: Unknown format code 'x'
body: <p>I am working on a program in Python and all the code looks good except when I run the program from the terminal I am getting the following error message:</p>
  
  <pre><code>Traceback (most recent call last):
    File "packetSniffer.py", line 25, in &lt;module&gt;
      main()
    File "packetSniffer.py", line 10, in main
      reciever_mac, sender_mac, ethernetProtocol, data = ethernet_frame(rawData)
    File "packetSniffer.py", line 17, in ethernet_frame
      return getMacAddress(reciever_mac), getMacAddress(sender_mac), socket.htons(protocol), data[14:]
    File "packetSniffer.py", line 21, in getMacAddress
      bytesString = map('{:02x}'.format, bytesAddress)
  ValueError: Unknown format code 'x' for object of type 'str'
  </code></pre>
  
  <p>Here is the code for my entire program so far, would anybody be able to help?</p>
  
  <pre><code>import struct
  import textwrap
  import socket
  
  def main():
      connection = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.ntohs(3))
  
      while True:
          rawData, address = connection.recvfrom(65535)
          reciever_mac, sender_mac, ethernetProtocol, data = ethernet_frame(rawData)
          print('\nEthernet Frame: ')
          print('Destination: {}, Source: {}, Protocol: {}'.format(reciever_mac, sender_mac, ethernetProtocol))
  
  # Unpack ethernet frame
  def ethernet_frame(data):
      reciever_mac, sender_mac, protocol = struct.unpack('! 6s 6s H', data[:14])
      return getMacAddress(reciever_mac), getMacAddress(sender_mac), socket.htons(protocol), data[14:]
  
  # Convert the Mac address from the jumbled up form from above into human readable format
  def getMacAddress(bytesAddress):
      bytesString = map('{:02x}'.format, bytesAddress)
      macAddress = ':'.join(bytesString).upper()
      return macAddress
  
  main()
  </code></pre>