(Python 2.7)
我有一个程序可以从服务器下载一个 .zip 文件,其中包含一个我想运行的 .app 文件。.zip 从服务器下载很好,尝试在 Python 之外提取它可以正常工作。但是,当我尝试从 Python 中提取 zip 文件时,.app 没有运行 - 它没有说文件已损坏或损坏,它根本不会启动。我已经用其他 .app 文件尝试过这个,我遇到了同样的问题,想知道是否有其他人以前遇到过这个问题以及解决它的方法?
我正在使用的代码:
for a in gArchives:
if (a['fname'].endswith(".build.zip") or a['fname'].endswith(".patch.zip")):
#try to extract: if not, delete corrupted zip
try :
zip_file = zipfile.ZipFile(a['fname'], 'r')
except:
os.remove(a['fname'])
for files in zip_file.namelist() :
#deletes local files in the zip that already exist
if os.path.exists(files) :
try :
os.remove(files)
except:
print("Cannot remove file")
try :
shutil.rmtree(files)
except:
print("Cannot remove directory")
try :
zip_file.extract(files)
except:
print("Extract failed")
zip_file.close()
我也尝试过使用 zip_file.extractall(),但我遇到了同样的问题。