- 论坛徽章:
- 2
|
import urllib
def reporthook(blocks_read,block_size,total_size):
if not blocks_read:
print 'Connection opened'
return
if total_size < 0:
print 'Read %d blocks (%d bytes)' % (blocks_read,blocks_read * block_size)
else:
amount_read=blocks_read*block_size
print 'Read %d blocks, or %d/%d' % (blocks_read,amount_read,total_size)
return
url=''
filename,msg=urllib.urlretrieve(url,reporthook=reporthook)
print 'File:',filename
print 'Headers:'
print msg
错误如下,这是什么原因呢
Traceback (most recent call last):
File "D:\Python2.7\lib\urllib.py", line 93, in urlretrieve
return _urlopener.retrieve(url, filename, reporthook, data)
File "D:\Python2.7\lib\urllib.py", line 239, in retrieve
fp = self.open(url, data)
File "D:\Python2.7\lib\urllib.py", line 207, in open
return getattr(self, name)(url)
File "D:\Python2.7\lib\urllib.py", line 344, in open_http
h.endheaders(data)
File "D:\Python2.7\lib\httplib.py", line 954, in endheaders
self._send_output(message_body)
File "D:\Python2.7\lib\httplib.py", line 814, in _send_output
self.send(msg)
File "D:\Python2.7\lib\httplib.py", line 776, in send
self.connect()
File "D:\Python2.7\lib\httplib.py", line 757, in connect
self.timeout, self.source_address)
File "D:\Python2.7\lib\socket.py", line 571, in create_connection
raise err
IOError: [Errno socket error] [Errno 10060] |
|