无法在python中下载和解压缩NVE

时间:2018-12-21 04:55:10

标签: python security

我试图从Internet下载文件并通过python解压缩,但是zipfile错误。当我尝试通过终端将其解压缩时,它会成功。 请帮助

 import requests 
 import re 
 from os import listdir
 from os.path import isfile
 import zipfile

 r = requests.get('https://nvd.nist.gov/vuln/data-feeds#JSON_FEED') 
 for filename in re.findall("nvdcve-1.0-[0-9]*\.json\.zip",r.text): 
 print(filename) 
 r_file = requests.get("https://static.nvd.nist.gov/feeds/json/cve/1.0/" +filename, stream=True)
 f = open(filename, 'wb')
 for chunk in r_file: 
    f.write(chunk)
 zip = zipfile.ZipFile(f.name)
 uncompressed = zfobj.read(zip)
 output.write(uncompressed)`

我收到此错误:

`File "cve-downloader.py", line 20, in <module>
  zip = zipfile.ZipFile(f.name)
  File "/usr/lib/python2.7/zipfile.py", line 793, in __init__
  self._RealGetContents()
  File "/usr/lib/python2.7/zipfile.py", line 834, in _RealGetContents
  raise BadZipfile, "File is not a zip file"
  zipfile.BadZipfile: File is not a zip file    `

当我尝试在终端上这样做时:

`unzip nvdcve-1.0-2018.json.zip 
  Archive:  nvdcve-1.0-2018.json.zip
  inflating: nvdcve-1.0-2018.json`

0 个答案:

没有答案