python socket connection error
Jan 1, 2014 at 3:23am UTC
so im writing an irc session class (its very rough right now. still fleshing it out) and got this error when i tried to test it:
dtscode@dtscode-Latitude-E6410:~/Desktop$ python irc.py
Traceback (most recent call last):
File "irc.py", line 101, in <module>
session.Connect()
TypeError: Connect() takes no arguments (1 given)
here is the code in question:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
#! /usr/bin/env python
# Modules to import
import socket # for connecting to the server
# IRC Session class to abstract the session
# (and make my life easier)
class IRC:
"" "IRC Session class to abstract the data" "" # irc class bio
# *private* data members
__Host__ = "irc.quakenet.org" # server to connect to
__Channel__ = "#cplusplus" # channel hosted by sever
__Port__ = 6667 # port to use
__ServerSocket__ = socket.socket() # socket to use to connect to host
__Nick__ = "DTSCode-Bot" # nickname when talking
__User__ = "DTSCode-Bot" # session username
__Pass__ = "pass" # session password (not neccesary)
__Info__ = "An irc bot class made by DTSCode" # bio about the user
# start setters
def SetHost(Server):
__Host__ = Server
return
def SetChannel(Channel):
__Channel__ = Channel
return
def SetPort(Port):
__Port__ = Port
return
def SetNick(Nickname):
__Nick__ = Nickname
return
def SetUser(Username):
__User__ = Username
return
def SetPass(Password):
__Pass__ = Password
return
def SetInfo(Bio):
__Info__ = Bio
return
# end setters
# start getters
def GetHost():
return __Host__
def GetChannel():
return __Channel__
def GetPort():
return __Port__
def GetNick():
return __Nick__
def GetUser():
return __User__
def GetPass():
return __Pass__
def GetInfo():
return __Info__
# end getters
# start misc functions
def Connect():
__ServerSocket__.connect((__Host__, __Port__))
return
def Join():
return
def GetNamesList():
return
def Send():
return
def Recv(Bytes = 1024):
print __ServerSocket__.recv(Bytes)
return
def Close():
__ServerSocket__.close()
return
def ParseCommand():
return
# end misc functions
session = IRC()
session.Connect()
session.Recv()
session.Close()
Jan 1, 2014 at 3:40am UTC
I am going to take a wild guess and say you are passing host and port to connect() on line 76 when connect() does not actually take any arguments. Perhaps those are passed as arguments to the socket constructor or initializer function?
Jan 1, 2014 at 3:53am UTC
no i figured it out. for whatever reason it wanted me to remove the function parathenses on lines 100-103 if i didnt pass arguments.
Jan 1, 2014 at 5:54am UTC
update: as it turns out, you have to explicitly put in self (which i think is the python equivalent to this) as an argument in class functions
Jan 1, 2014 at 8:29am UTC
DTSCode wrote:update: as it turns out, you have to explicitly put in self (which i think is the python equivalent to this) as an argument in class functions
Yes, but you should not pass them when calling a class function.
DTSCode wrote:for whatever reason it wanted me to remove the function parathenses on lines 100-103 if i didnt pass arguments.
That sounds odd, what version of python are you using?
Jan 1, 2014 at 8:40am UTC
2.7.3, but now im suspect if it actually worked or just ran without errors.
Yes, but you should not pass them when calling a class function.
oh yes i know. i just meant that it would be like this in c++
int myclass::afunc(this )
. i deduced from my code and the errors that it is passed implicitly
Topic archived. No new replies allowed.