I develop an import system that supports popular geoformats. Sometimes I get a DriverError reading GeoPackage files with geopandas, but at times it works well.
My code is simple:
gdf = gpd.read_file(file)
Traceback (most recent call last): File "fiona/_shim.pyx", line 83, in fiona._shim.gdal_open_vector
File "fiona/_err.pyx", line 291, in fiona._err.exc_wrap_pointer fiona._err.CPLE_AppDefinedError: unable to open database file: this file is a WAL-enabled database. It cannot be opened because it is presumably read-only or in a read-only directory.
During handling of the above exception, another exception occurred:
File "/path/backend/layers/services/load_data.py", line 47, in file_to_geodataframe gdf = gpd.read_file(file)
File "/path/venv1/lib/python3.10/site-packages/geopandas/io/file.py", line 201, in _read_file with reader(path_or_bytes, **kwargs) as features:
File "/path/venv1/lib/python3.10/site-packages/fiona/collection.py", line 555, in init
super(BytesCollection, self).init(self.virtual_file, vsi=filetype, **kwds) File "/path/venv1/lib/python3.10/site-packages/fiona/collection.py", line 162, in init
File "fiona/ogrext.pyx", line 540, in fiona.ogrext.Session.start
File "fiona/_shim.pyx", line 90, in fiona._shim.gdal_open_vector
fiona.errors.DriverError: unable to open database file: this file is a WAL-enabled database. It cannot be opened because it is presumably read-only or in a read-only directory.
What should I do? I'm make tests this with some files that have the same permissions and are placed in the same directory.
Why are some files readable and others not? Am I doing something wrong or is it a file problem?
I found a solution that works for me. The first argument in the read_file function is the file path or file object.
filename : str, path object or file-like object Either the absolute or relative path to the file or URL to be opened, or any object with a read() method (such as an open file or StringIO)
I used file object and got this error. After I changed the first argument to the path reading worked as I expected.