Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/343.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 获取远程zip文件并列出其中的文件_Python_Google App Engine_Zip - Fatal编程技术网

Python 获取远程zip文件并列出其中的文件

Python 获取远程zip文件并列出其中的文件,python,google-app-engine,zip,Python,Google App Engine,Zip,我正在进行一个小型的Google应用程序引擎项目,在该项目中,我需要从URL获取一个远程zip文件,然后列出zip存档中包含的文件 我正在使用zipfile模块 以下是我到目前为止的想法: # fetch the zip file from its remote URL result = urlfetch.fetch(zip_url) # store the contents in a stream file_stream = StringIO.StringIO(result.content)

我正在进行一个小型的Google应用程序引擎项目,在该项目中,我需要从URL获取一个远程zip文件,然后列出zip存档中包含的文件

我正在使用
zipfile
模块

以下是我到目前为止的想法:

# fetch the zip file from its remote URL
result = urlfetch.fetch(zip_url)

# store the contents in a stream
file_stream = StringIO.StringIO(result.content)

# create the ZipFile object
zip_file = zipfile.ZipFile(file_stream, 'w')

# read the files by name
archive_files = zip_file.namelist()
不幸的是,
archive\u files
列表的长度始终为0


你知道我做错了什么吗?

你正在打开
ZipFile
进行写作。请尝试阅读。

您正在使用
w
权限打开文件,这会截断文件。将其更改为
r
阅读权限:

zip_file = zipfile.ZipFile(file_stream, 'r')
参考: