当我输入help
时,我将客户端连接到服务器我得到了AttributeError:'_ Helper'对象没有属性'encode'
这是完整的输出
-:-:-:-:-:Server:-:-:-:-:-
Connection from: ('127.0.0.1', 58675)
Your Instruction: help
Traceback (most recent call last):
File "serverback.py", line 36, in <module>
msg = msg.encode("UTF-8")
AttributeError: '_Helper' object has no attribute 'encode'
这是我的python脚本
#imports
import socket
import os
import sys
#Variables
port = int(sys.argv[1])
#Functions
def clear():
os.system('cls' if os.name=='nt' else 'clear')
#Starting Server
serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
host = socket.gethostname()
serversocket.bind((host, port))
serversocket.listen(1)
clear()
print("-:-:-:-:-:Py Server:-:-:-:-:-")
clientsocket, addr = serversocket.accept()
print("Connection from: " + str(addr))
while True:
msg = input("Your Instruction: ")
if msg == "help":
clear()
print("-+-+-+-+-+HELP+-+-+-+-+-")
print("Test Connection: 'test'")
input("\nPress ENTER to continue")
clear()
print("-:-:-:-:-:Py Server:-:-:-:-:-")
else:
msg = msg.encode("UTF-8")
clientsocket.send(msg)
msg = clientsocket.recv(4096)
print(msg.decode("UTF-8"))