dnspython模块报错 AttributeError: 'CNAME' object has no attribute 'address'
有时候用到这个模块的时候会报错
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'的更多相关文章
- py+selenium 明明定位不到元素,但却不报错或是报错AttributeError: 'list' object has no attribute 'click'【已解决】
问题:定位不到元素,但却不报错或者出现报错AttributeError: 'list' object has no attribute 'click' 如图 或者 解决方法: 将”driver ...
- python文件名不要跟模块名相同,报错AttributeError: 'module' object has no attribute 'Differ'
python中的文件都会生成pyc文件,包括模块也是这样,所以调用模块的时候,实际上会调用模块.pyc文件:在这个前提下,如果将文件名命名成跟模块名一样,在同一目录下就会生成一个跟模块名一样的pyc文 ...
- 关于flask登录视图报错AttributeError: '_AppCtxGlobals' object has no attribute 'user'
在一个小程序中写了一个登录视图函数,代码如下: @app.route('/login',methods = ['GET','POST']) @oid.loginhandler def login(): ...
- Django2.2报错 AttributeError: 'str' object has no attribute 'decode'
准备将 Django 连接到 MySQL,在命令行输入命令 python manage.py makemigrations 后报错: AttributeError: 'str' object has ...
- 运行pytest,报错"AttributeError: 'module' object has no attribute 'xxx'"
最近学习pytest被此问题困扰,敲脑壳,实在是不该.百度解决方法一大堆,我的问题怎么也解决不了,来看一下,我是怎么解决的,各位大佬勿喷,只是自己做笔记用,谢谢. 报错信息如下: 网上解决方法是这样的 ...
- 机器学习实战:KNN代码报错“AttributeError: 'dict' object has no attribute 'iteritems'”
报错代码: sortedClassCount = sorted(classCount.iteritems(), key=operator.itemgetter(1), reverse=True) 解决 ...
- python报错“AttributeError: 'set' object has no attribute 'items'“
作为才开始学爬虫的萌新,遇到了一个这样的错,很懵逼 后面到网络到处查看大佬的解决方法,才发现headers的请求头部信息有错误,headers是一个字典,不是字符串,所以报错了 原代码 headers ...
- [已解决]报错:报错AttributeError: 'int' object has no attribute 'upper'
原因:openpyxl版本低,需升级 pip install --upgrade openpyxl
- Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法
最近在编写Python脚本过程中遇到一个问题比较奇怪:Python脚本完全正常没问题,但执行总报错"AttributeError: 'module' object has no attrib ...
随机推荐
- Leetcode 78题-子集
LeetCode 78 网上已经又很多解这题的博客了,在这只是我自己的解题思路和自己的代码: 先贴上原题: 我的思路: 我做题的喜欢在本子或别处做写几个示例,以此来总结规律:下图就是我从空数组到数组长 ...
- 【JavaWeb】【Eclipse】使用Eclipse创建我的第一个网页
使用Eclipse创建我的第一个网页 哔哩哔哩 萌狼蓝天 你可以直接点击Finish,也可以点击Next,到下面这个界面后,勾选生成web.xml然后Finish(你不这样做就会没有Web.xml文件 ...
- last显示出unknown用户
这问题是群里有朋友发了一张照片看到的: 出现问题第一时间当然是百度或者谷歌,结果还是查到了,原来是gdm作怪,也可以认为是bug 该用户由GDM创建(可能是由于错误).并不是真的有"未知&q ...
- CF764B Timofey and cubes 题解
Content 有一个序列 \(a_1,a_2,a_3,...,a_n\),对于 \(i\in[1,n]\),只要 \(i\leqslant n-i+1\),就把闭区间 \([i,n-i+1]\) 内 ...
- CF1469D Ceil Divisions 题解
Content 你有一个长度为 \(n\) 的数组 \(a\),初始时,\(\forall i\in[1,n]\),\(a_i=i\). 每次操作选择两个数 \(x,y(1\leqslant x,y\ ...
- python 快速启动http监听服务
python3 [root@vm10-20-9-45 ~]# python3 -m http.server 2378 Serving HTTP on 0.0.0.0 port 2378 (http:/ ...
- FastJsonHttpMessageConverter请求中参数序列化问题排查
问题 前几天帮忙其他部门的多个祖先级项目改造开发,服务间使用Feign方式调用,发现接口提供方接收到的请求,没有请求参数,经过排查发现服务调用方的FastJsonHttpMessageConverte ...
- ffmpeg(1)之libavutil/common.h:30:2: error: missing -D__STDC_CONSTANT_MACROS / #define __STDC_CONSTANT_MACROS
说明 编译环境: mac osx 10.14 + cmake + clang++ 写了一个简单c++的范例调用ffmpeg函数完成音频采集 出错提示 [build] /usr/local/ffmpeg ...
- 《Java必须知道的300个问题》读书总结
这本书是在图书馆随便逛的时候找到的书.花了一下午看完了,感觉有用的地方不是很多,大部分都是些概念,并没有太大用途.不过里边有些东西还是可以看一看的,总结如下. Java语言基础 1.表达式3-2.6= ...
- 【LeetCode】239. Sliding Window Maximum 解题报告(Python&C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 单调递减队列 MultiSet 日期 题目地址:ht ...