코드를 실행하는 동안 다음 오류가 발생합니다. 다음 코드 조각은 다음과 같습니다."AttributeError : 'bytes'객체에 'encode'속성이 없습니다."
import time;
from socket import*
from pip._vendor.distlib.compat import raw_input
pingCount = 0
minTime = 0
maxTime = 0
counter = 0
totalTime = 0
message = 'test'
packetsLost = 0
#Sends 10 pingcounts as setup_testing_defaults
while pingCount < 11:
counter +=1
#Creates a UDP Socket
clientSocket = socket(AF_INET, SOCK_DGRAM)
#Sets timeout value for each one to 1 second
#The timeout function determines how long till it expires
clientSocket.settimeout(1)
#Creating the paramaters for sendTo
#SendTo sends the ping to the socket
clientSocket.sendto(message.encode("utf-8"),('127.0.0.1',12000))
#time() yields the current time in milliseconds
start = time.time()
#Trying to print data received from the server
try: #etc...
코드는, 반복이 몇 (일반적으로 최대 3 실행 위에서 언급 한 오류와 충돌하기 전에 내가 지금 어떤 제안이 좋지 않을까 무슨 일이 일어나고 있는지 너무 확실하지 않다, ! 감사
을, 'message'는 아마도'bytes' 타입입니다. 물론 인코딩 방법이 없습니다. –
이 코드는 저에게 효과적입니다. 어쩌면 그것은 시도 후 코드인가? – Hugal31
문제의 코드가 오류를 나타내지 않는다는보고를 기반으로 투표를 종료합니다. 또한 들여 쓰기 문제가 있습니다. 'while' 명령 다음의 코드는 실제로 'while' 루프에 포함될 다른 수준의 들여 쓰기가 필요합니다. 수정하지 않으면 코드에서 구문 오류가 발생합니다. – jpmc26