Skip to content

Confusing error messages when reading/writing NetCDF files from/to UTF-8 directories #171

@tyralla

Description

@tyralla
>>> import netCDF4, os

>>> os.mkdir("ärgerlich")
>>> netCDF4.Dataset(os.path.join("ärgerlich", "filename.nc"), "w")
Traceback
...
PermissionError: [Errno 13] Permission denied: 'ärgerlich\\filename.nc'

>>> os.mkdir("aergerlich")
>>> netCDF4.Dataset(os.path.join("aergerlich", "filename.nc"), "w")
<class 'netCDF4.Dataset'>
root group (NETCDF4 data model, file format HDF5):
    dimensions(sizes):
    variables(dimensions):
    groups:

This is not a HydPy bug and I don't think we can circumvent it. However, we should add useful information to our error messages. An example of the current behaviour:

>>> from hydpy.core.testtools import prepare_full_example_1
>>> prepare_full_example_1("ärgerlich")
>>> from hydpy import HydPy, pub
>>> hp = HydPy("ärgerlich/HydPy-H-Lahn")
>>> hp.prepare_network()
>>> pub.timegrids = "1996-01-01", "1997-01-01", "1d"
>>> hp.prepare_models()
>>> hp.prepare_inputseries()
>>> pub.sequencemanager.filetype = "nc"
>>> hp.load_inputseries()
Traceback
...
FileNotFoundError: While trying to read data from NetCDF file `...ärgerlich\HydPy-H-Lahn\series\default\hland_96_input_p.nc`, the following error occurred: [Errno 2] No such file or directory: '...ärgerlich\\HydPy-H-Lahn\\series\\default\\hland_96_input_p.nc'

See Unidata/netcdf4-python#941 and https://forum.hdfgroup.org/t/non-english-characters-in-hdf5-file-name/4627/3.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions