Trying to set up some basic socket code in Python (well, Jython, but I don't think that's relevant here).
import socket
class Foo(object):
def __init__(self):
#some other init code here
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect("localhost", 2057)
s.send("Testing 1,2,3...")
data = s.recv()
s.close()
print data
It tells me:
s.connect("localhost", 2057) File "<string>", line 1, in connect TypeError: connect() takes exactly 2 arguments (3 given)
I get the feeling something really simple is staring me in the face, but I can't tell what I'm doing wrong.
You have to pass a Tuple to connect()
method.
s.connect( ('localhost', 2057) )
The first (implicit) argument expected is self
, the second is the Tuple.
You are passing three arguments! s
is being passed as the implicit first argument, and the other two arguments you have specified are the second and third arguments.
Now, the reason that it's upset is because socket.connect()
only takes one argument (two, of course, if you count the implicit instance argument): see the docs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With