2013-09-25 38 views
0
from zipfile import ZipFile 


fzip=ZipFile("crackme.zip") 
fzip.extractall(pwd=b"mysecretpassword") 

脚本只对IDLE,但是当我在命令行运行它,它显示:Python3:ZipFile的实例没有属性 'extractall'

unzip.py

fzip.extractall(PWD = B “mysecretpassword”)

      ^

语法错误:无效的语法

有什么不对?

+1

你_sure_你正在使用Python 3? extractall()方法是在2.6中添加的,所以之前的版本不会有。 –

+0

我工作的Python 3.3.0 – user2816162

+0

你可能会考虑提出一个新的问题,因为你的问题的标题是不再相关。 –

回答

1

它的工作原理(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') 

BTW,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 documentation

Warning Never extract archives from untrusted sources without prior inspection. It is possible that files are created outside of path, e.g. members that have absolute filenames starting with "/" or filenames with two dots "..".

Changed in version 3.3.1: The zipfile module attempts to prevent that. See extract() note.

+0

我编辑了这个问题。在命令提示符下运行脚本时仍然存在问题 – user2816162

相关问题