When i try to create a netcdf-file with a filepath, that contains Non-ASCII-characters, Netcdf4 creates broken filenames on windows, because it encodes the filepath in UTF8, which is fine for Linux,. In Windows, the filepath has to be convertet to CP1252.
import netCDF4 as nc4
filepath = r'C:\Plön.nc'
ds = nc4.Dataset(filepath, 'w')
ds.close()
this creates a file
Plön.nc
I could try to avoid Non-ASCII-Characters in .nc filenames, but if i want to create a file in the folder
C:\Plön\
import netCDF4 as nc4
filepath = r'C:\Plön\Ploen.nc'
ds = nc4.Dataset(filepath, 'w')
ds.close()
then i get the confusing error message:
builtins.OSError: Permission denied
Because the folder "Plön" is not recognized correctly.
The solution would be to pass the filesystemencoding to _strencode in
_netCDF4.pyx in line 1796
- bytestr = _strencode(str(filename))
+ bytestr = _strencode(str(filename), encoding=sys.getfilesystemencoding())
I'll create a pull request.
Max
When i try to create a netcdf-file with a filepath, that contains Non-ASCII-characters, Netcdf4 creates broken filenames on windows, because it encodes the filepath in UTF8, which is fine for Linux,. In Windows, the filepath has to be convertet to CP1252.
this creates a file
Plön.nc
I could try to avoid Non-ASCII-Characters in .nc filenames, but if i want to create a file in the folder
C:\Plön\
then i get the confusing error message:
builtins.OSError: Permission denied
Because the folder "Plön" is not recognized correctly.
The solution would be to pass the filesystemencoding to _strencode in
_netCDF4.pyx in line 1796
I'll create a pull request.
Max