Python AttributeError: ‘module’ object has no attribute ‘A’

来源:互联网 发布:怎么看淘宝卖家信誉 编辑:程序博客网 时间:2024/05/21 21:36

from: https://dolrblog.wordpress.com/2016/08/24/python-attributeerror-module-object-has-no-attribute-a/



Python AttributeError: ‘module’ object has no attribute ‘A’

One day I am writing a script digging DNS records. A weird error appears during testing:

<class 'dns.rdtypes.ANY.CNAME.CNAME'> Traceback (most recent call last): File "C:\Users\xyz\test.py", line 65, in <module> if isinstance(rr, dns.rdtypes.IN.A.A): AttributeError: 'module' object has no attribute 'A'

The related code is:

import dns.resolver......if rrset:  for rr in rrset:    if isinstance(rr, dns.rdtypes.IN.A.A):      print 'DNS A record:' + domain_name + ':' + rr.address    elif isinstance(rr, dns.rdtypes.ANY.CNAME.CNAME):      print 'DNS CNAME record:' + domain_name + ':' + rr.target.to_text()

It turns out that, if an instance of class “dns.rdtypes.IN.A.A” is never generated before this “if isinstnace()” line. Python won’t know the class “dns.rdtypes.IN.A.A”. Thus it will raise the error.

So the solution is to explicitly import dns.rdtypes.IN.A, or manually create an A record before the isinstance() check.






0 0