我有一个脚本,我从网站下载一堆Zip文件(150+)并解压缩。我只是注意到Zip文件没有完全解压缩 - 即每个目录中应该有68个文件,而且只有62个。脚本运行良好,没有错误。
有什么想法?我尝试自己运行一个Zip文件,它提取得很好。操作可以超时还是什么?请原谅我的代码,我是新手。
我正在运行Python 2.7。
import csv, urllib, urllib2, zipfile
from datetime import date
dlList =[]
dloadUrlBase = r"https://websoilsurvey.sc.egov.usda.gov/DSD/Download/Cache/SSA/"
dloadLocBase = r"Z:/Shared/Corporate/Library/GIS_DATA/Soils/"
stateDirList =[]
countyDirList =[]
fileNameList=[]
unzipList =[]
extractLocList=[]
logfile = 'log_{}.txt'.format(date.today())
with open(r'N:\Shared\Service Areas\Geographic Information Systems\Tools and Scripts\Soil_Downloads\FinalListforDownloads.csv') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
stateDirList.append(row['StateDir'])
countyDirList.append(row['CountyDir'])
fileNameList.append(row['File_Name'])
for state, county, fileName in zip(stateDirList, countyDirList, fileNameList):
dloadDir = dloadLocBase + state + r"/" + county + "/" + fileName
requestURL = dloadUrlBase + fileName
extractLocList.append(dloadLocBase + state + r"/" + county + "/")
try:
urllib.urlretrieve(requestURL, dloadDir)
print requestURL + " found"
urllib.urlcleanup()
unzipList.append(dloadDir)
f = open(logfile, 'a+')
f.write(dloadDir + " has been downloaded")
f.close()
except:
pass
for zFile, uzDir in zip(unzipList, extractLocList):
zip_ref = zipfile.ZipFile(zFile, "r")
zip_ref.extractall(uzDir)
zip_ref.close()
答案 0 :(得分:0)
不是仅在发生错误时传递,而是记录/打印错误。这应该表明问题或一系列问题。
除了例外e: 打印e#或打印e.message
答案 1 :(得分:0)
原来这是我的网络存在同步问题。我们使用与我们的办公室同步的基于云的网络,因此以某种方式并非所有文件都已同步并留在队列中。