Reason for socket.error

Posted by August Flanagan on Stack Overflow See other posts from Stack Overflow or by August Flanagan
Published on 2010-05-26T21:19:20Z Indexed on 2010/05/26 21:21 UTC
Read the original article Hit count: 207

Filed under:
|

Hi,

I am a complete newbie when it comes to python, and programming in general. I've been working on a little webapp for the past few weeks trying to improve my coding chops. A few days ago my laptop was stolen so I went out and got a new MacBook Pro. Thank God I had everything under subversion control. The problem is now that I am on my new machine a script that I was running has stopped working and I have no idea why.

This is really the only part of what I have been writing that I borrowed heavily for existing scripts. It is from the widely available whois.py script and I have only slightly modified it as follows (see below). It was running fine on my old system (running ubuntu), but now the socket.error is being raised. I'm completely lost on this, and would really appreciate any help. Thanks!

def is_available(domainname, whoisserver="whois.verisign-grs.com", cache=0):


if whoisserver is None:
    whoisserver = "whois.networksolutions.com"

  s = None

  while s == None:
    try:
      s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
      s.setblocking(0)
      try:
        s.connect((whoisserver, 43))
      except socket.error, (ecode, reason):
        if ecode in (115, 150): pass
        else:
          raise socket.error, (ecode, reason)
      ret = select.select([s], [s], [], 30)

      if len(ret[1])== 0 and len(ret[0]) == 0:
        s.close()
        raise TimedOut, "on connect "
      s.setblocking(1)

    except socket.error, (ecode, reason):
      print ecode, reason
      time.sleep(1)
      s = None


  s.send("%s \n\n" % domainname)
  page = ""
  while 1:
    data = s.recv(8196)
    if not data: break
    page = page + data

  s.close()

© Stack Overflow or respective owner

Related posts about python

Related posts about sockets