IOError:[Errno 5]输入/输出错误:

时间:2014-05-27 23:20:33

标签: python-2.7 exception

我从网上下载了很多文件。代码根据文件名创建要下载文件的路径。事实是我有IOError:[Errno 5]输入/输出错误。下载文件时,此错误会随机出现。下载100个文件后第一次出现,下次下载约1400个文件后。我不知道为什么。这是我写的代码。任何帮助表示赞赏。

感谢。

  

文件“download.py”,第13行,在downloadFile中

     
    

output.write(wmvfile.read())

         
      

output = open(str(path)+ name +'。wmv','wb)

    
  
    def downloadFile(url, name, path):
      try: 
        wmvfile = urllib2.urlopen(url)
        global count
        count += 1
        print count
        print "path: ", path, "name: ", name
        output = open(str(path) + name + '.wmv', 'wb')
        output.write(wmvfile.read())
        output.close()

      except urllib2.HTTPError as e:
        print 'url error :', url
        path = '/Volumes/Ross/PoliticsVideos/logfile/httperror/'

        if not os.path.exists(os.path.dirname(path)):
           os.makedirs(os.path.dirname(path))

        with open(path + 'log.txt', 'a') as output:
           output.write(url + '\n')
           output.close()

      except IOError as io:
        print 'IO error:', url
        path = '/Volumes/Ross/PoliticsVideos/logfile/ioerror/'
        if not os.path.exists(os.path.dirname(path)):
           os.makedirs(os.path.dirname(path))

        with open(path + 'log.txt', 'a') as output:
           output.write(url + '\n')
           output.close()

0 个答案:

没有答案
相关问题