Building a packet to send to a minecraft server - python -


i've been trying hours (literally) send packet minecraft server. http://www.minecraftwiki.net/wiki/classic_server_protocol#packet_protocol (the player identification bit). i'm getting error 'struct.error: argument 's' must bytes object'. here's code: packet = struct.pack('bb8s110sb', 0, 7, username, verification_key, 0) # packet type s.send(packet)

how can send player identification packet server?

any appreciated , not able reply answers @ least 12 hours when posted. +rep help, :)

the struct's pack function requires username , verification_key byte objects.

in python 3 when define string so, 'asdf', encoded using unicode. in order support many encodings python has byte object. convert strings byte objects have call encode method desired encoding argument. in case 'ascii' work both of variables so,

packet = struct.pack('bb8s110sb', 0, 7, username.encode('ascii'), verification_key.encode('ascii'), 0)

should solve problem.


Comments

Popular posts from this blog

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -