2

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)

Error:

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

self.session.start(self, **kwargs)

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?

Filepath:

/homedir/uploads/8371906e-162c-42fc-b56d-5e434ae6878c.gpkg

Update:

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.

2
  • SQLite supports different journal modes and one of those is WAL sqlite.org/wal.html. Read the whole document, it is also explaining the Read-Only databases. If a GeoPackage that is in WAL mode is read-write and it is placed into a media and directory with read-write rights then geopandas should be able to read it.
    – user30184
    May 26 at 20:38
  • 2
    You can answer your own question : gis.stackexchange.com/help/self-answer May 27 at 9:02

1 Answer 1

2

Adding the OP's solution here so this thread is marked as answered:

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.

1
  • I had similar issue. I wrote a script using geopandas to open shapefiles(geojson and shp). It was able to read some files and some others not. It gave a similar error in th eoriginal post. By using the full name path it worked/opened on all the files.
    – mapperx
    Jul 19 at 13:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.