tags:

views:

30

answers:

1

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()
A: 

Works fine for me, though it doesn't ever return anything. (Linux 2.6.32)

c4757p
And as far as I know, the socket interface on Mac is the same. I know it sounds dumb, but are you sure you're connected to the Internet when you run this?
c4757p
yeah I am. ;) I can also telnet the whois server on port 43 and connect to it that way, so I know that it isn't a connection issue. When I run it I end up here :except socket.error, (ecode, reason): print ecode, reason time.sleep(1) s = NoneAnd it just loops through the error message.
August Flanagan