2016-01-24 49 views
0

我試圖在Python中實現Server List Ping。特定的數據包結構位於上述鏈接處,類型和通用數據包結構爲here。我的代碼是here。但是,當我嘗試運行代碼,它給了我這個錯誤:對int進行struct.pack時TypeError?

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

我也試過圍繞0x00int(),但無濟於事。

回答

1

從頁面:https://docs.python.org/2/library/struct.html
struct.pack(FMT,V1,V2,...) - 返回包含值V1,V2的字符串,...

所以你試圖把字符串轉換成字節數組,這顯然不起作用。將字節放入陣列中而不使用包功能或使用:

handshakeBytes += pack(whatever) 

表示法。

+0

嗯,謝謝!但是,我將如何獲得非VarInt的正確性? (即字符串和無符號短) – robbie0630

+0

使用+ =運算符。 – nsilent22

+0

啊,沒有明白。 – robbie0630

相關問題