robbie
robbie

Reputation: 1309

TypeError when doing struct.pack on an int?

I am trying to implement Server List Ping in Python. The specific packet structures are at the above link, and the types and generic packet structure are here. My code is here. But when I try to run that code, it gives me this error:

Traceback (most recent call last):
  File "ddos.py", line 6, in <module>
    handshakeBytes.append(pack('<i', 0x00))
TypeError: an integer is required

I also tried surrounding 0x00 with int(), but to no avail.

Upvotes: 0

Views: 370

Answers (1)

nsilent22
nsilent22

Reputation: 2863

From the page: https://docs.python.org/2/library/struct.html
struct.pack(fmt, v1, v2, ...) - Return a string containing the values v1, v2, ...

So you're trying to put string into byte array, which obviously won't work. Put your bytes into the array without using pack function or use:

handshakeBytes += pack(whatever)

notation.

Upvotes: 1

Related Questions