[英]TypeError: a bytes-like object is required not 'str'
import socket
connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
connection.connect(("192.168.152.140", 4444))
connection.send("\n[+] connection established.\n")
connection.close()
尝试这个
connection.send("\n[+] connection established.\n".encode())
这应该工作
您的 connection.send 参数需要是字节,但您传递的是一个字符串。 您应该在发送之前对其进行编码,例如 message.encode('utf-8')
message = "\n[+] connection established.\n";
connection.send(message.encode('utf-8'));
socket.send
function 需要字节,而不是字符串( 文档)
您需要在发送前将字符串转换为字节: https://www.askpython.com/python/string/python-string-bytes-conversion
它应该看起来像这样:
connection.send("\n[+] connection established.\n".encode("utf-8"))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.