f=open(filename,'wb')
user_agent='Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'
header={'User-Agent':user_agent}
req=urllib2.Request(i[0],headers=header)
resp=urllib2.urlopen(req)
data=resp.read()
f.write(data)
f.close()
time.sleep(10)
Traceback (most recent call last):
File "get_taobao_mm.py", line 36, in <module>
sp.get_info()
File "get_taobao_mm.py", line 29, in get_info
resp=urllib2.urlopen(req)
File "C:\Python26\lib\urllib2.py", line 124, in urlopen
return _opener.open(url, data, timeout)
File "C:\Python26\lib\urllib2.py", line 383, in open
response = self._open(req, data)
File "C:\Python26\lib\urllib2.py", line 401, in _open
'_open', req)
File "C:\Python26\lib\urllib2.py", line 361, in _call_chain
result = func(*args)
File "C:\Python26\lib\urllib2.py", line 1130, in http_open
return self.do_open(httplib.HTTPConnection, req)
File "C:\Python26\lib\urllib2.py", line 1105, in do_open
raise URLError(err)
urllib2.URLError: <urlopen error [Errno 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or esta
C:\Users\qabuilder\rocky\cache\code>
经常返回以上错误,请问有什么办法可以避免? 按道理已经设置了sleep 10 可以避开ddos了呀
是不是urllib也需要close函数才行????