Newly added opener argument and subsequent behavior #1479
-
I was trying out the newly added @sgillies explained that The IssueWhen creating and writing to new file by passing a Steps to reproduce the problem.Below is the script to reproduce the problem. First the common part of the script followed by variations and subsequent outcomes. Common Code Sectionimport fiona
import fsspec
from fiona.crs import from_epsg
fs = fsspec.filesystem(protocol="s3", key="KKKKKKKKKK", secret="XXXXXXXXXXXXX")
schema = {
'geometry': 'Polygon',
'properties': {
'id': 'int',
'name': 'str'
}
}
# Create some sample polygons
polygons = [
{
'geometry': {
'type': 'Polygon',
'coordinates': [[(0, 0), (0, 1), (1, 1), (1, 0), (0, 0)]]
},
'properties': {
'id': 1,
'name': 'square'
}
},
{
'geometry': {
'type': 'Polygon',
'coordinates': [[(2, 2), (2, 3), (3, 2), (2, 2)]]
},
'properties': {
'id': 2,
'name': 'triangle'
}
}
] Export to GeoJSONwith fiona.open(
's3://bucket/path/vector_layer.geojson',
'w',
driver='GeoJSON',
crs=from_epsg(4326),
schema=schema,
opener=fs
) as dst:
for polygon in polygons:
dst.write(polygon)
print("Write Completed Successfully!") OutputWrite Completed Successfully! Export to GPKGwith fiona.open(
's3://bucket/path/vector_layer.gpkg',
'w',
driver='GPKG',
crs=from_epsg(4326),
schema=schema,
opener=fs
) as dst:
for polygon in polygons:
dst.write(polygon)
print("Write Completed Successfully!") Output---------------------------------------------------------------------------
CPLE_OpenFailedError Traceback (most recent call last)
File fiona/ogrext.pyx:175, in fiona.ogrext.gdal_create()
File fiona/_err.pyx:291, in fiona._err.exc_wrap_pointer()
CPLE_OpenFailedError: sqlite3_open(/vsis3/bucket/path/vector_layer.gpkg) failed: unable to open database file
During handling of the above exception, another exception occurred:
DriverError Traceback (most recent call last)
Cell In[45], line 1
----> 1 with fiona.open(
2 's3://bucket/path/vector_layer.gpkg',
3 'w',
4 driver='GPKG',
5 crs=from_epsg(4326),
6 schema=schema,
7 opener=fs
8 ) as dst:
9 for polygon in polygons:
10 dst.write(polygon)
File ~/.micromamba/envs/PyDev/lib/python3.12/site-packages/fiona/env.py:457, in ensure_env_with_credentials.<locals>.wrapper(*args, **kwds)
454 session = DummySession()
456 with env_ctor(session=session):
--> 457 return f(*args, **kwds)
File ~/.micromamba/envs/PyDev/lib/python3.12/site-packages/fiona/__init__.py:303, in open(fp, mode, driver, schema, crs, encoding, layer, vfs, enabled_drivers, crs_wkt, allow_unsupported_drivers, **kwargs)
292 colxn = Collection(
293 path,
294 mode,
(...)
300 **kwargs
301 )
302 elif mode == "w":
--> 303 colxn = Collection(
304 path,
305 mode,
306 crs=crs,
307 driver=driver,
308 schema=schema,
309 encoding=encoding,
310 layer=layer,
311 enabled_drivers=enabled_drivers,
312 crs_wkt=crs_wkt,
313 allow_unsupported_drivers=allow_unsupported_drivers,
314 **kwargs
315 )
316 else:
317 raise ValueError("mode string must be one of {'r', 'w', 'a'}")
File ~/.micromamba/envs/PyDev/lib/python3.12/site-packages/fiona/collection.py:246, in Collection.__init__(self, path, mode, driver, schema, crs, encoding, layer, vsi, archive, enabled_drivers, crs_wkt, ignore_fields, ignore_geometry, include_fields, wkt_version, allow_unsupported_drivers, **kwargs)
244 elif self.mode in ("a", "w"):
245 self.session = WritingSession()
--> 246 self.session.start(self, **kwargs)
247 except OSError:
248 self.session = None
File fiona/ogrext.pyx:1110, in fiona.ogrext.WritingSession.start()
File fiona/ogrext.pyx:1111, in fiona.ogrext.WritingSession.start()
File fiona/ogrext.pyx:179, in fiona.ogrext.gdal_create()
DriverError: sqlite3_open(/vsis3/bucket/path/vector_layer.gpkg) failed: unable to open database file Export to ESRI Shapefilewith fiona.open(
's3://bucket/path/vector_layer.shp',
'w',
driver='ESRI Shapefile',
crs=from_epsg(4326),
schema=schema,
opener=fs
) as dst:
for polygon in polygons:
dst.write(polygon)
print("Write Completed Successfully!") Output---------------------------------------------------------------------------
CPLE_AppDefinedError Traceback (most recent call last)
File fiona/ogrext.pyx:1239, in fiona.ogrext.WritingSession.start()
File fiona/ogrext.pyx:1240, in fiona.ogrext.WritingSession.start()
File fiona/_err.pyx:291, in fiona._err.exc_wrap_pointer()
CPLE_AppDefinedError: Failed to create file /vsis3/bucket/path/vector_layer.shp: Permission denied
During handling of the above exception, another exception occurred:
DriverIOError Traceback (most recent call last)
Cell In[46], line 1
----> 1 with fiona.open(
2 's3://bucket/path/vector_layer.shp',
3 'w',
4 driver='ESRI Shapefile',
5 crs=from_epsg(4326),
6 schema=schema,
7 opener=fs
8 ) as dst:
9 for polygon in polygons:
10 dst.write(polygon)
File ~/.micromamba/envs/PyDev/lib/python3.12/site-packages/fiona/env.py:457, in ensure_env_with_credentials.<locals>.wrapper(*args, **kwds)
454 session = DummySession()
456 with env_ctor(session=session):
--> 457 return f(*args, **kwds)
File ~/.micromamba/envs/PyDev/lib/python3.12/site-packages/fiona/__init__.py:303, in open(fp, mode, driver, schema, crs, encoding, layer, vfs, enabled_drivers, crs_wkt, allow_unsupported_drivers, **kwargs)
292 colxn = Collection(
293 path,
294 mode,
(...)
300 **kwargs
301 )
302 elif mode == "w":
--> 303 colxn = Collection(
304 path,
305 mode,
306 crs=crs,
307 driver=driver,
308 schema=schema,
309 encoding=encoding,
310 layer=layer,
311 enabled_drivers=enabled_drivers,
312 crs_wkt=crs_wkt,
313 allow_unsupported_drivers=allow_unsupported_drivers,
314 **kwargs
315 )
316 else:
317 raise ValueError("mode string must be one of {'r', 'w', 'a'}")
File ~/.micromamba/envs/PyDev/lib/python3.12/site-packages/fiona/collection.py:246, in Collection.__init__(self, path, mode, driver, schema, crs, encoding, layer, vsi, archive, enabled_drivers, crs_wkt, ignore_fields, ignore_geometry, include_fields, wkt_version, allow_unsupported_drivers, **kwargs)
244 elif self.mode in ("a", "w"):
245 self.session = WritingSession()
--> 246 self.session.start(self, **kwargs)
247 except OSError:
248 self.session = None
File fiona/ogrext.pyx:1248, in fiona.ogrext.WritingSession.start()
DriverIOError: Failed to create file /vsis3/bucket/path/vector_layer.shp: Permission denied Demonstrably, the creation of both Operating systemMacOS 15.2 (24C101) [Kernel: Darwin 24.2.0] Fiona and GDAL version and provenance
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
@digital-idiot in trying to reproduce this, I've run into the same issue you found at fsspec/s3fs#925. GDAL's vector drivers are rather different in their writing implementations. For some, like Shapefile, a local temporary directory that is later uploaded to S3 may be required. |
Beta Was this translation helpful? Give feedback.
@digital-idiot it's not the auxiliary files themselves, but the incremental writes to them. We can copy data to S3 (using HTTP PUT), but we can't generally write or append.
There's a new exception that I haven't had the opportunity to try: https://aws.amazon.com/about-aws/whats-new/2024/11/amazon-s3-express-one-zone-append-data-object/. I suspect GDAL/OGR, fsspec, etc are not ready to take advantage of that.