我是靠谱客的博主 坚强鞋垫,这篇文章主要介绍python3 urllib2 报错raise AttributeError, attr SyntaxError: invalid syntax,现在分享给大家,希望可以做个参考。

使用python3经常会出现关于urllib2的一些问题,urllib2是python2里面的,这里代码出错往往是因为引用了urllib2。
解决办法,找到报错的文件,找到出错代码,比如我下面报错的信息:
于是打开mldata.py找到12行

try:
    # Python 2
    from urllib2 import urlopen
    from urllib2 import HTTPError
except ImportError:
    # Python 3+
    from urllib.request import urlopen
    from urllib.error import HTTPError

把关于urllib2的代码删除。

 # Python 3+
    from urllib.request import urlopen
    from urllib.error import HTTPError

问题就解决了。

最后

以上就是坚强鞋垫最近收集整理的关于python3 urllib2 报错raise AttributeError, attr SyntaxError: invalid syntax的全部内容,更多相关python3内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(55)

评论列表共有 0 条评论

立即
投稿
返回
顶部