Socket problems

Jonathon Sisson sisson.j at gmail.com
Sun Jul 13 20:52:18 CEST 2008


SSL objects use "write", not "send".

You also need to change this:

self.sock.write('NICK %s\r\n') % self.nick

to this:

self.sock.write('NICK %s\r\n' % self.nick)

If you don't, the interpreter will bomb on trying to concatenate the 
return value for "write" (an integer) with the string self.nick.

Hope this helps...

Jonathon

jjbutler88 at gmail.com wrote:
> I am trying to write a simple python IRC client, roughly following
> this guide: http://www.devshed.com/c/a/Python/Python-and-IRC/
>
> I have written some code, which uses the same commands as the guide,
> but I get this error:
> Traceback (most recent call last):
>   File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
> python2.5/threading.py", line 486, in __bootstrap_inner
>     self.run()
>   File "pythonirc.py", line 31, in run
>     self.sock.send('NICK %s\r\n') % self.nick
> AttributeError: send
>
> Here is my code so far:
> [code]
> #!/usr/bin/env python
>
> from socket import *
> from threading import Thread
> import sys
>
> class IRCBot(Thread):
>     def __init__(self, host, room, nick, port=6667, ssl=0):
>         Thread.__init__(self)
>         self.host = host
>         self.port = port
>         self.ssl = ssl
>         self.room = room
>         self.nick = nick
>         self.sock = socket(AF_INET, SOCK_STREAM)
>
>     def run(self):
>         print "Connecting..."
>         try:
>             self.sock.connect((self.host, self.port))
>         except:
>             print "Could not connect to %s" % self.host
>             sys.exit(1)
>         if self.ssl:
>             try:
>                 self.sock = ssl(self.sock)
>             except:
>                 print "Server does not suport SSL"
>                 sys.exit(1)
>
>         self.sock.send('NICK %s\r\n') % self.nick
>         self.sock.send('USER PyIRC PyIRC PyIRC :Python IRC\r\n')
>         self.sock.send('JOIN #%s\r\n') % self.room
>         while True:
>             data = self.sock.recv(4096)
>             if data.find('PING') != -1:
>                 self.sock.send('PONG' + data.split()[1]+'\r\n')
>             print data
>
>     def close(self):
>         self.sock.send('PART #%s\r\n') % self.room
>         self.sock.send('QUIT\r\n')
>         self.sock.shutdown(SHIT_RDWR)
>         self.sock.close()
>
> IRCBot('irc.psych0tik.net','hbh', 'pythonircclient',6697,1).start()
> [/code]
>
> Anyone know why it might be doing this? Config problem?
>
> Thanks in advance,
> Jon
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>   




More information about the Python-list mailing list