无法从 url 读取压缩文件

Unable to read zipped file from url

我无法从 Web 打开压缩文件。

from urllib.request import urlopen
from io import BytesIO
from zipfile import ZipFile
url = "http://..../craft.zip"
file = urlopen(url).read()
file = BytesIO(file)
document = ZipFile(file)
content = document.read('MASTER.txt')

当我尝试打印一些数据时,我得到了一堆数字。该 zip 中还有其他 txt 文件,当我替换内容中的文件名时,我得到了相同的输出。虽然我读了py3k: How do you read a file inside a zip file as text, not bytes?,但我不知道如何修复它。

问题出在压缩文件的方法上:

from urllib.request import urlopen
from io import BytesIO
from zipfile import ZipFile

url = "http://....craft.zip"
file = urlopen(url).read()
file = BytesIO(file)
document = ZipFile(file)
content = document.open('MASTER.txt', "r")
for line in content:
        print(line)

此代码解决了我的问题,我能够在 zip 文件中查找数据。 Read 已被 open 取代。