有时候用到这个模块的时候会报错

AttributeError: 'CNAME' object has no attribute 'address'

如下所示

[root@ansible ch01]# ./dnspython_ex1.py
Please input a domain: www.baidu.com
Traceback (most recent call last):
File "./dnspython_ex1.py", line 9, in <module>
print(j.address)
AttributeError: 'CNAME' object has no attribute 'address'

代码是这样的:

#!/usr/bin/env python
import dns.resolver domain = raw_input('Please input a domain: ')
A = dns.resolver.query(domain, 'A')
for i in A.response.answer:
for j in i.items:
print j.address

我们只需在最后需要输出address时在前面增加if判断

if j.rdtype == 1:

将代码修改如下:

#!/usr/bin/env python
import dns.resolver domain = raw_input('Please input a domain: ')
A = dns.resolver.query(domain, 'A')
for i in A.response.answer:
for j in i.items:
if j.rdtype == 1:
print j.address

运行就不会报错了

[root@ansible ch01]# ./dnspython_ex1.py
Please input a domain: www.baidu.com
14.215.177.38
14.215.177.39

dnspython模块报错 AttributeError: 'CNAME' object has no attribute 'address'的更多相关文章

  1. py+selenium 明明定位不到元素,但却不报错或是报错AttributeError: 'list' object has no attribute 'click'【已解决】

    问题:定位不到元素,但却不报错或者出现报错AttributeError: 'list' object has no attribute 'click' 如图  或者  解决方法:   将”driver ...

  2. python文件名不要跟模块名相同,报错AttributeError: 'module' object has no attribute 'Differ'

    python中的文件都会生成pyc文件,包括模块也是这样,所以调用模块的时候,实际上会调用模块.pyc文件:在这个前提下,如果将文件名命名成跟模块名一样,在同一目录下就会生成一个跟模块名一样的pyc文 ...

  3. 关于flask登录视图报错AttributeError: '_AppCtxGlobals' object has no attribute 'user'

    在一个小程序中写了一个登录视图函数,代码如下: @app.route('/login',methods = ['GET','POST']) @oid.loginhandler def login(): ...

  4. Django2.2报错 AttributeError: 'str' object has no attribute 'decode'

    准备将 Django 连接到 MySQL,在命令行输入命令 python manage.py makemigrations 后报错: AttributeError: 'str' object has ...

  5. 运行pytest,报错"AttributeError: 'module' object has no attribute 'xxx'"

    最近学习pytest被此问题困扰,敲脑壳,实在是不该.百度解决方法一大堆,我的问题怎么也解决不了,来看一下,我是怎么解决的,各位大佬勿喷,只是自己做笔记用,谢谢. 报错信息如下: 网上解决方法是这样的 ...

  6. 机器学习实战:KNN代码报错“AttributeError: 'dict' object has no attribute 'iteritems'”

    报错代码: sortedClassCount = sorted(classCount.iteritems(), key=operator.itemgetter(1), reverse=True) 解决 ...

  7. python报错“AttributeError: 'set' object has no attribute 'items'“

    作为才开始学爬虫的萌新,遇到了一个这样的错,很懵逼 后面到网络到处查看大佬的解决方法,才发现headers的请求头部信息有错误,headers是一个字典,不是字符串,所以报错了 原代码 headers ...

  8. [已解决]报错:报错AttributeError: 'int' object has no attribute 'upper'

    原因:openpyxl版本低,需升级 pip install --upgrade openpyxl

  9. Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法

    最近在编写Python脚本过程中遇到一个问题比较奇怪:Python脚本完全正常没问题,但执行总报错"AttributeError: 'module' object has no attrib ...

随机推荐

  1. IDE常用插件

    IDE 常用插件集合 :

  2. SQL Server 2014如何DATEDIFF()函数截取对应时间年月日

    4.1 定义和用法: DATEDIFF()函数返回两个日期之间的时间 4.2 语法 DATEDIFF(datepart,startdate,enddate) datepart值: year | qua ...

  3. GIT最基本使用

    带'*':必须操作 不带'*':可能需要而且经常用的 常见步骤为下: *1.克隆项目:有两种不同类型的网址(https/ssh) git clone [url] *2.初始化本地仓库 git init ...

  4. IDT系统中断描述表以及绕过Xurtr检测的HOOK姿势

    什么是中断?  指当出现需要时,CPU暂时停止当前程序的执行转而执行处理新情况的程序和执行过程.即在程序运行过程中,系统出现了一个必须由CPU立即处理的情况,此时,CPU暂时中止程序的执行转而处理这个 ...

  5. 动态导入模块__import__("str") importlib标准库

    解释器内部使用的为__import__('str') #!/usr/bin/env python # Author:Zhangmingda print('我是aa类 ') #被import的时候就执行 ...

  6. STL源码剖析-智能指针shared_ptr源码

    目录一. 引言二. 代码实现 2.1 模拟实现shared_ptr2.2 测试用例三. 潜在问题分析 你可能还需要了解模拟实现C++标准库中的auto_ptr一. 引言与auto_ptr大同小异,sh ...

  7. 阿里巴巴分布式服务框架HSF

    HSF称之为高速服务框架HSF(High-speed Service Framework),是在阿里巴巴广泛使用的分布式RPC服务框架. HSF连通不同的业务系统,解耦系统间的实现依赖.HSF从分布式 ...

  8. 一篇文章讲明白vue3的script setup,拥抱组合式API!

    引言 vue3除了Composition API是一个亮点之外,尤大大又给我们带来了一个全新的玩意 -- script setup,对于setup大家相信都不陌生,而对于script setup有些同 ...

  9. C# 金额数字转中文的方法

    /// <summary> /// 金额数字转大写(带小数点) /// </summary> public static string PriceToCn(decimal pr ...

  10. IDEA中springboot项目添加yml格式配置文件

    1.先创建application.properties 文件,在resources文件夹,右键 new -> Resource Bundle  如下图所示,填写名称 2.生成如下图所示文件 3. ...