相关疑难解决方法(0)

使用Python创建加密的ZIP文件

我在Python 2.5中使用ZipFile创建一个ZIP文件,它到目前为止工作正常:

import zipfile, os

locfile = "test.txt"
loczip = os.path.splitext (locfile)[0] + ".zip"
zip = zipfile.ZipFile (loczip, "w")
zip.write (locfile)
zip.close()
Run Code Online (Sandbox Code Playgroud)

但我找不到如何加密ZIP文件中的文件.我可以使用系统并调用PKZIP -s,但我想必须有更"Pythonic"的方式.我正在寻找一个开源解决方案.

python zip

32
推荐指数
5
解决办法
3万
查看次数

如何使用 Python 将文件压缩为受密码保护的存档

有没有办法压缩gzipzipfile作为密码保护的存档?以下是示例代码,说明如何在没有密码保护的情况下归档文件:

import gzip, shutil

filepath = r'c:\my.log'

with gzip.GzipFile(filepath + ".gz", "w") as gz:
    with open(filepath) as with_open_file:
        shutil.copyfileobj(with_open_file, gz)

import zipfile

zf = zipfile.ZipFile(filepath + '.zip', 'w')
zf.write(filepath)
zf.close()
Run Code Online (Sandbox Code Playgroud)

python passwords zip gzip archive

6
推荐指数
1
解决办法
6885
查看次数

创建受密码保护的zip文件Python

我正在使用以下代码在的Python34应用程序中根据用户上传的文件创建受密码保护的zip文件zipFile。但是,当我从Windows打开zip文件时,它不会要求输入密码。稍后,我将使用相同的密码从python读取zip文件。我究竟做错了什么?

这是我的代码:

pwdZipFilePath = uploadFilePath + "encryptedZipFiles/"
filePath = uploadFilePath

if not os.path.exists(pwdZipFilePath):        
      os.makedirs(pwdZipFilePath)

#save csv file to a path
fd, filePath = tempfile.mkstemp(suffix=source.name, dir=filePath)

with open(filePath, 'wb') as dest:
    shutil.copyfileobj(source, dest)

#convert that csv to zip
fd, pwdZipFilePath = tempfile.mkstemp(suffix=source.name + ".zip", dir=pwdZipFilePath)

with zipfile.ZipFile(pwdZipFilePath, 'w') as myzip:
    myzip.write(filePath)

    myzip.setpassword(b"tipi")
Run Code Online (Sandbox Code Playgroud)

python django zipfile python-3.x

4
推荐指数
2
解决办法
8227
查看次数

Python-zipfile:如何为zipfile设置密码?

我在(sav.zip)中有一个zip文件,我正在尝试为其设置密码:

zf = zipfile.ZipFile(“ sav.zip”)

zf.setpassword(“ 1234”)

但是...我收到TypeError:预期的字节数,得到了str

我的错在哪里

python zipfile

2
推荐指数
1
解决办法
9384
查看次数

标签 统计

python ×4

zip ×2

zipfile ×2

archive ×1

django ×1

gzip ×1

passwords ×1

python-3.x ×1