Error reading Dfsu file (non-ascii filepath)

Open
#23 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
python
Domain
backend

Research direction

Reproduce the failure with the non-ASCII path from the report, then inspect mikeio/dfsu.py around _read_dfsu_header and mikecore/DfsuFile.py and DfsFile.py around Open. Trace the filename encoding path and verify that opening a DFSU file with non-ASCII characters succeeds without the UnicodeEncodeError.

Written by the indexing model from the issue text.

Description

Here is my code:
“”“
from mikeio import Dfsu

dfs = Dfsu("D:\01项目\03合界数模\02方案前计算\03数模计算\F0\F0.m21fm - Result Files\F0 Q=2230.dfsu")
ds = dfs.read()
print(ds)
”“”
The following bugs appear:
“”“
Traceback (most recent call last):
File "D:\MIKE_Cal_PostPro(new)\01Data_Write.idea\123.py", line 4, in
dfs = Dfsu("D:\\F0\F0.m21fm - Result Files\F0 Q=2230.dfsu")
File "D:\ProgramData\miniconda3\lib\site-packages\mikeio\dfsu.py", line 2176, in init
self._read_header(self._filename)
File "D:\ProgramData\miniconda3\lib\site-packages\mikeio\dfsu.py", line 2087, in _read_header
self._read_dfsu_header(filename)
File "D:\ProgramData\miniconda3\lib\site-packages\mikeio\dfsu.py", line 2108, in _read_dfsu_header
dfs = DfsuFile.Open(filename)
File "D:\ProgramData\miniconda3\lib\site-packages\mikecore\DfsuFile.py", line 297, in Open
dfs.Open(fileName, DfsFileMode.Read);
File "D:\ProgramData\miniconda3\lib\site-packages\mikecore\DfsFile.py", line 726, in Open
fnp.value = filename.encode("cp1252")
File "D:\ProgramData\miniconda3\lib\encodings\cp1252.py", line 12, in encode
return codecs.charmap_encode(input,errors,encoding_table)
UnicodeEncodeError: 'charmap' codec can't encode characters in position 5-6: character maps to
”“”

Dominant language
Python
Stars
5
Forks
1
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from DHI/mikecore-python

All issues in DHI/mikecore-python

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.