为了账号安全,请及时绑定邮箱和手机立即绑定

<type 'exceptions.AttributeError'>这到底是哪里错了

<type 'exceptions.AttributeError'>这到底是哪里错了

守候你守候我 2019-02-26 10:05:33
python 报错 Exception in thread Thread-1 (most likely raised during interpreter shutdown): Traceback (most recent call last): File "/usr/lib/python2.6/threading.py", line 532, in __bootstrap_inner File "/usr/lib/python2.6/threading.py", line 484, in run File "dxcad.py", line 243, in threadget File "dxcad.py", line 181, in gethtml File "/usr/lib/python2.6/urllib2.py", line 126, in urlopen File "/usr/lib/python2.6/urllib2.py", line 391, in open File "/usr/lib/python2.6/urllib2.py", line 409, in _open File "/usr/lib/python2.6/urllib2.py", line 369, in _call_chain File "/usr/lib/python2.6/urllib2.py", line 1190, in http_open File "/usr/lib/python2.6/urllib2.py", line 1164, in do_open <type 'exceptions.AttributeError'>: 'NoneType' object has no attribute 'error' 代码 def gethtml(url): encoding_support = ContentEncodingProcessor prodom=proxylist[random.randint(0,proxn)] proxy_support = urllib2.ProxyHandler({'http':prodom}) opener = urllib2.build_opener(proxy_support,encoding_support,urllib2.HTTPHandler) urllib2.install_opener(opener) try: bpanhtml = urllib2.urlopen(url,timeout = 2).read() except Exception,e: print e return gethtml(url) return bpanhtml 求教
查看完整描述

1 回答

?
慕哥6287543

TA贡献1831条经验 获得超10个赞

不要在线程中 install_opener

urllib2.install_opener(opener)
Install an OpenerDirector instance as the default global opener. Installing an opener is only necessary if you want urlopen to use that opener; otherwise, simply call OpenerDirector.open() instead of urlopen(). The code does not check for a real OpenerDirector, and any class with the appropriate interface will work.

查看完整回答
反对 回复 2019-03-01
  • 1 回答
  • 0 关注
  • 620 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信