我想从url下载一个zipfile并保存到某个地方。我不想提取我的文件,这是我的问题。我有一个下载zipfile和提取文件的代码,但我只想下载和保存。我应该改变什么?
from urllib.request import urlopen
from zipfile import ZipFile
zipurl = 'https://opendata.geoportal.gov.pl/prg/adresy/PunktyAdresowe/POLSKA.zip'
with urlopen(zipurl) as zipresp:
with ZipFile(BytesIO(zipresp.read())) as zfile:
zfile.extractall(r'/home/gis/adresypolska')
Error:
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
File "/usr/lib/python3.8/http/client.py", line 471, in read
s = self._safe_read(self.length)
File "/usr/lib/python3.8/http/client.py", line 612, in _safe_read
data = self.fp.read(amt)
File "/usr/lib/python3.8/socket.py", line 669, in readinto
return self._sock.recv_into(b)
File "/usr/lib/python3.8/ssl.py", line 1241, in recv_into
return self.read(nbytes, buffer)
File "/usr/lib/python3.8/ssl.py", line 1099, in read
return self._sslobj.read(len, buffer)
OverflowError: signed integer is greater than maximum发布于 2021-01-11 21:36:06
只是根本不要使用ZipFile。你有了文件内容,写出来:
zipurl = 'https://opendata.geoportal.gov.pl/prg/adresy/PunktyAdresowe/POLSKA.zip'
with open('POLSKA.zip', 'wb') as f:
f.write(urlopen(zipurl).read())要以块的形式读取和保存,如果RAM较小,请执行以下操作:
with open('POLSKA.zip', 'wb') as f:
with urlopen(zipurl) as zipresp:
while True:
chunk = zipresp.read(1024)
if not chunk: break
f.write(chunk)这将在每次迭代中读取1024个字节,您应该根据需要进行相应的更改。
https://stackoverflow.com/questions/65667843
复制相似问题