I'm trying to open Sentinel-2 bands directly from the .zip L2A files with GDAL, but this only returns a None. Unzipping the folder prior to reading the file yield better results, but still randomly returns some None from time to time. I'm using gdal 2.2.2.
import numpy as np import osgeo.gdal as gdal import zipfile, os from libs.generic import filemanager as fm os.environ['CPL_ZIP_ENCODING'] = 'UTF-8' class s2img: def __init__(self): return None def readL2A(self, zippath): try: zipf = zipfile.ZipFile(zippath, 'r') except: raise IOError("Unable to open ZIP-file.") flist = zipf.namelist() zipf.close() bandnames =  bandnames.append( ['B02','B03','B04','B08'] ) bandnames.append( ['B05','B06','B07','B8A','B11','B12','SCL'] ) bandnames.append( ['B01','B09'] ) bandres = ['10m','20m','60m'] fnames = [f for f in flist if 'IMG_DATA' in f] fnames = [f for f in fnames if f.endswith('.jp2')] for r in range(len(bandnames)-1): res = bandres[r] resbnames = bandnames[r] fresnames = [f for f in fnames if res in f] for b in range(len(resbnames)): fname= [f for f in fresnames if resbnames[b] in f ] chn_fn = "/vsizip/%s/%s" % (zippath,fname) gobj = gdal.Open(chn_fn, gdal.GA_ReadOnly ) # DO STUFF return None