Skip to content

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

Open

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.

Activity

  1. tyralla commented on Jul 4, 2025

    @tyralla
    MemberAuthor

    Maybe I was too pessimistic, and changing the working directory temporarily could fix the issue:

    >>> import netCDF4, os
    
    >>> os.mkdir("ärgerlich")
    >>> os.chdir("ärgerlich")
    >>> netCDF4.Dataset("nicht ärgerlich.nc", "w")
    <class 'netCDF4.Dataset'>
    root group (NETCDF4 data model, file format HDF5):
        dimensions(sizes): 
        variables(dimensions): 
        groups: 
  2. tyralla commented on Jul 24, 2026

    @tyralla
    MemberAuthor

    Maybe I was too pessimistic, and changing the working directory temporarily could fix the issue:

    I played around with this idea, but now I think we should stick to emitting more helpful error messages. Changing the working directory temporarily does not work in combination with the just-in-time reading/writing mode. The alternative of moving or copying files to/from a temporary directory appears to be fragile and not worth it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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