Python - Sending Packets issuing error - Minecraft Packets
Question: **I'm using the following script:**

    
    
    import socket
    import struct
    
    username = "username_value"
    verification_key = "verification_key"
    
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)  # boilerplate
    s.connect(("example.com", 1234))  # adjust accordingly
    
    # now for the packet
    # note that the String type is specified as having a length of 64, we'll pad that
    
    packet = ""
    
    packet += struct.pack("B", 1)  # packet type
    packet += struct.pack("B", 7)  # protocol version
    packet += "%-64s" % username  # magic!
    packet += "%-64s" % verification_key
    packet += struct.pack("B", 0)  # that unused byte, assuming a NULL byte here
    
    # send what we've crafted
    s.send(packet)
    

**and getting a response of:**

    
    
        packet += struct.pack("B", 1)  # packet type
    TypeError: Can't convert 'bytes' object to str implicitly
    

**I am almost brand-new to Python, and just started, but I understand the
language. I read up and found something about Python 3 changing the way you
use packets. I feel kind of hopeless. Help? Thank you**


Answer: In python 3 you have to implicitly define your string `packet` as a bytes

    
    
    packet = b""
    

instead of `packet = ""`

