开发者社区> 问答> 正文

为什么打e.code报错?报错

import urllib.request

req=urllib.request.Request('http://www.baibai.com')
try:
    urllib.request.urlopen(req)
except urllib.request.URLError as e:
    print(e.code)

python3.3版本

报错为

Traceback (most recent call last):
  File "D:\Program\5.19-5.23\test03\__init__.py", line 7, in <module>
    print(e.code)
AttributeError: 'URLError' object has no attribute 'code'




展开
收起
爱吃鱼的程序员 2020-06-20 17:33:19 776 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    错误说明都有了,对象没有这个属性啊第六行用HTTPError,但是我看别人执行没有问题,是python版本的问题吗第六行
    <divclass="linenumber6index5alt1">excepturllib.request.HTTPErrorase:

    2020-06-20 17:33:37
    赞同 展开评论 打赏
问答分类:
问答地址:
相关产品:
问答排行榜
最热
最新

相关电子书

更多
Data Pre-Processing in Python: 立即下载
低代码开发师(初级)实战教程 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载