-1

I'm new to Python and while creating a client-server UDP ping server program in Python I encountered this severe error. It says:

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

The error is present in the UDPClient.py file, which is:

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)
user2607744
  • 339
  • 5
  • 14

1 Answers1

0

This error is caused by trying to combine str and tuple in an unsupported way

eg:

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

I don't think the code sample you included is doing this though

John La Rooy
  • 295,403
  • 53
  • 369
  • 502