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

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

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

求教


不要在线程中 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.

【热门文章】
【热门文章】