[Tutor] Python Whois [was Re: Tutor Digest, Vol 134, Issue 86]

Steven D'Aprano steve at pearwood.info
Sun Apr 26 01:07:31 CEST 2015


Hi Jon,

Before I answer your question, first some mailing list housekeeping. If 
you are going to read and respond to messages here, please change from 
"Daily Digest" to individual messages. Your reply includes 500 
lines (about 10 or 12 pages!) of old messages. We've already seen those 
messages before, we don't need to see them again. And most of them have 
nothing to do with your question.

This is what happens when you reply to Digests. It is annoying to the 
reader, and for those people who pay for internet access by the byte 
(yes, there are still some of them) it costs them money. So please don't 
do it in the future.


Now, back to your question:


On Sat, Apr 25, 2015 at 02:13:50PM -0400, Juanald Reagan wrote:

> Okay, so it doesn't look like that worked...here is the traceback. I don't
> understand the second part of your request.
> 
> Jons-desktop:whois-0.7 2 jon$ python pythonwhois.py
> 
> 8.8.8.8
> 
> Traceback (most recent call last):
> 
>   File "pythonwhois.py", line 14, in <module>
> 
>     print results.asn_registry
> 
> AttributeError: 'dict' object has no attribute 'asn_registry'

Try these three lines instead:

     print type(results)
     print results
     print results['asn_registry']


The first two lines are to find out what sort of object the IPWhois 
result is, and hopefully what its contents are. I *think* it will be a 
dict, in which case the last line may be the answer you are looking for: 
to extract the 'asn_registry' field from the dict, you will use

    results['asn_registry']

Assuming that works, does it answer your question? If not, can you 
explain what you want to do?



-- 
Steve


More information about the Tutor mailing list