1
我與客戶機到服務器的連接,當我進入help
我得到AttributeError的:「_Helper」對象有沒有屬性「編碼」AttributeError的:「_Helper」對象有沒有屬性「編碼」
這是完整的輸出
-:-:-:-:-: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"))
謝謝你的人,我希望你得到你應得 –
謝謝我明白,幸福。 –