2014-10-06 1 views
-1

저는 Python을 처음 접했고 클라이언트 - 서버 UDP ping 서버 프로그램을 파이썬에서 만들 때이 심각한 오류가 발생했습니다. 그것은 말한다 :'tuple'객체를 암시 적으로 str로 변환 할 수 없습니다.

from socket import * 
from datetime import * 
from time import * 

pings = 10 
i =0 
server = '127.0.0.1' 
servPort = 5369 
clientSock = socket(AF_INET, SOCK_DGRAM) 
data = 'ping' 
databin = bytes(data, 'UTF-8') 
while i<pings: 
    print("Print number: ",i) 
    i += 1 
    before = datetime.now() 
    clientSock.sendto(databin, (server, servPort)) 
    clientSock.settimeout(1) 

    try: 
     clientMsgm server = cliendSock.recvfrom(1024) 
     after = datetime.now() 
     diff = before - after 
     if(i==10): 
      print("Ping", i) 

    except timeout: 
     print("Ping",i," Request timed out!!!") 


Traceback (most recent call last): 

File "D:\...\UDPClient.py", line 18, in <module> 
clientSock.sendto(databin,server, servPort) # Send what (i.e.'ping') and to whom and where 
TypeError: an integer is required (got type str) 
+1

어떤 줄에서 오류가 발생합니까? –

+0

'databin '을 할당했을 때't '가 빠졌습니까? – squiguy

+0

파이썬 버전을 사용하고있는 전체 추적을 게시 하시겠습니까? –

답변

0

이 오류는 지원되지 않는 방식으로

strtuple을 결합하는 시도로 인해 발생 :

TpyeError: Can't convert 'tuple' object to str implicitly 

오류가있는 UDPClient.py 파일에 존재 예 :

Python 3.3.2+ (default, Feb 28 2014, 00:52:16) 
[GCC 4.8.1] on linux 
Type "help", "copyright", "credits" or "license" for more information. 
>>> "foo" + ("bar",) 
Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
TypeError: Can't convert 'tuple' object to str implicitly 

내가 포함 된 코드 샘플은이 작업을 수행하고 있다고 생각하지 않습니다. gh

+0

어떻게해야합니까? uptil 4 ping이 제대로 작동하지만 그 다음에 오류가 표시됩니다! – user2607744

관련 문제