from zipfile import ZipFile
fzip=ZipFile("crackme.zip")
fzip.extractall(pwd=b"mysecretpassword")
该脚本仅适用于 IDLE,但是当我从命令行运行它时,它显示:
解压.py
fzip.extractall(pwd=b"mysecretpassword")
^
SyntaxError:无效的语法
怎么了?
from zipfile import ZipFile
fzip=ZipFile("crackme.zip")
fzip.extractall(pwd=b"mysecretpassword")
该脚本仅适用于 IDLE,但是当我从命令行运行它时,它显示:
解压.py
fzip.extractall(pwd=b"mysecretpassword")
^
SyntaxError:无效的语法
怎么了?
它可以工作(Ubuntu 13.04):
>>> import sys
>>> sys.version
'3.3.1 (default, Apr 17 2013, 22:32:14) \n[GCC 4.7.3]'
>>> from zipfile import ZipFile
>>> f = ZipFile('a.zip')
顺便说一句,pwd
应该是字节对象:
>>> f.extractall(pwd="mysecretpassword")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.3/zipfile.py", line 1225, in extractall
self.extract(zipinfo, path, pwd)
File "/usr/lib/python3.3/zipfile.py", line 1213, in extract
return self._extract_member(member, path, pwd)
File "/usr/lib/python3.3/zipfile.py", line 1275, in _extract_member
with self.open(member, pwd=pwd) as source, \
File "/usr/lib/python3.3/zipfile.py", line 1114, in open
raise TypeError("pwd: expected bytes, got %s" % type(pwd))
TypeError: pwd: expected bytes, got <class 'str'>
>>> f.extractall(pwd=b'mysecretpassword')
>>>
根据zipfile.ZipFile.extractall
文件:
警告未经事先检查,切勿从不受信任的来源提取档案。文件可能是在路径之外创建的,例如具有以“/”开头的绝对文件名或带有两个点“..”的文件名的成员。
在 3.3.1 版更改: zipfile 模块试图阻止这种情况。见
extract()
注。