python - 如何在python中读取所有zipfile
问题描述
例如,我有一个 zipfile,我更改了 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)
但是这段代码抛出异常,导致代码预期参数“名称”将一些文件读入 zip 我如何读取所有 zip 文件以加密并保存?
解决方案
.write
使用方法时,您实际上应该指定 zipfile 的名称。
最后一行是
db_file.write(encrypted_data, zipfile)
推荐阅读
- javascript - 如何发出 HTTP 请求将文件从 reactjs 上传到谷歌驱动器?
- gcc - 使用 gcc 编译时对“WinMain@16”错误的未定义引用
- node.js - 使用节点 js 验证巴西手机号码
- javascript - 如何提高 javascript 数组操作中嵌套循环的性能?
- xml - 将 XML 发布到 WebAPI
- css - 在可滚动父项的情况下,工具提示文本不可见
- php - Laravel 5.7 中使用 ajax 的 MethodNotAllowedHttpException 错误
- excel - 如何根据条件复制粘贴数据?
- python - 找出 FTP 上时间 A 和时间 B 的目录列表之间的差异
- scikit-learn - 为什么随机森林中的更多特征会显着降低准确性?