wormwood_3 wrote:
> Hi all,
> 
> I am new to Python programming and this list, looks like a great place so far!
> 
> Recently I was trying to do a "try: X except Y: Z" statement, checking for a 
> custom error code that the rwhois.py module throws. Some details on the 
> exercise and the full code can be found on this post ( 
> http://assistedsilicon.blogspot.com/2007/08/fun-with-python-domainspotter.html
>  ). So, here is what I tried:
> 
>         for potdomain in self.potdomains:
>             try: 
>                 who.whois(potdomain)
>                 self.availdomains.append(potdomain)
>             except 'NoSuchDomain':
>                 pass
>             self.totalchecked+=1
> 
> If you need more context, the whole program is here (
http://assistedsilicon.blogspot.com/2007/08/fun-with-python-domainspotter.html#code
). I first tried simply "except NoSuchDomain", since that was what I saw
rwhois throw when I sent it a domain that was not registered. That did
not work, so I quoted it. I got a warning that throwing a string
exception is deprecated, but the check did not work anyway. Am I trying
to check for this custom error wrongly? How should it be done?

Probably you need to import NoSuchDomain from rwhois:
from rwhois import WhoisRecord, NoSuchDomain

then use
   except NoSuchDomain:

In general, when you ask a question here, "I tried X and it did not 
work" is not very informative and makes it difficult to give a good 
answer. It is very helpful to show the actual code you tried and the 
actual error message, including the full traceback. The error message 
and traceback include a lot of very helpful information; including them 
will greatly improve your chance of a correct answer.

Kent
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to