Why do i get this error:
Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
self.run()
File "/usr/lib/python2.7/threading.py", line 754, in run
self.__target(*self.__args, **self.__kwargs)
File "/usr/lib/python2.7/urllib2.py", line 435, in open
response = meth(req, response)
File "/usr/lib/python2.7/urllib2.py", line 542, in http_response
code, msg, hdrs = response.code, response.msg, response.info()
AttributeError: 'str' object has no attribute 'code'
import urllib2
import threading
class MyHandler(urllib2.HTTPHandler):
def http_response(self, req, response):
return response.getcode()
o = urllib2.build_opener(MyHandler())
t = threading.Thread(target=o.open, args=('http://www.google.com/',))
t.start()
t.join()