###print images
for i , (img , Type) in enumerate(ActualImages):
try:
req = urllib.request.Request(img,headers={'User-Agent' : header})
raw_img = urllib.request.urlopen(req).read().decode("utf-8")
cntr = len([i for i in os.listdir(DIR) if image_type in i]) + 1
print (cntr)
if len(Type)==0:
f = open(os.path.join(DIR , image_type + "_"+ str(cntr)+".jpg"), 'wb')
else :
f = open(os.path.join(DIR , image_type + "_"+ str(cntr)+"."+Type), 'wb')
f.write(raw_img)
f.close()
except Exception as e:
print ("could not load : "+img)
print (e)
这是我的代码的一部分,该代码已从python2.7脚本转换为python3,所以我可能不知道有什么区别。有人知道它的作用吗?
这是错误回溯: enter image description here