问题描述
我有一个zip文件 例如,我更改了zip中的一些文件,我需要对其进行加密,然后保存
def encrypt(self,zipfile: ZipFile):
import base64
with open(self.__db_path,'wb') as db_file:
decrypted_data = zipfile.read()
aes = AES.new(self.key,AES.MODE_OFB)
encrypted_data = aes.encrypt(decrypted_data)
with open(self.__db_path,'wb') as db_file:
db_file.write(encrypted_data)
但是此代码引发异常,导致代码预期参数“ name”将某些文件读入zip 我如何读取所有zip文件以对其进行加密和保存?
解决方法
使用.write
方法时,您实际上应该指定zipfile的名称。
最后一行是
db_file.write(encrypted_data,zipfile)