Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error reading Dfsu file (non-ascii filepath) #23

Open
tanyibo-cnb opened this issue Mar 6, 2022 · 4 comments
Open

Error reading Dfsu file (non-ascii filepath) #23

tanyibo-cnb opened this issue Mar 6, 2022 · 4 comments

Comments

@tanyibo-cnb
Copy link

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
”“”

@jsmariegaard
Copy link
Member

Does it work if copy the file to the current directory first?

dfs = Dfsu("F0 Q=2230.dfsu")

@ecomodeller ecomodeller changed the title Error reading mesh file Error reading Dfsu file (non-ascii filepath) Mar 7, 2022
@jsmariegaard jsmariegaard transferred this issue from DHI/mikeio May 9, 2022
@aka863
Copy link

aka863 commented Sep 18, 2022

In DfsFile.py,
change
fnp.value = filename.encode("cp1252")
to
fnp.value = filename.encode("cp936")
it will work.

@aka863
Copy link

aka863 commented Sep 18, 2022

Because the path name contain chinese character,
and the OS is Windows,
the filename can't be encoded in cp1252.

@aka863
Copy link

aka863 commented Sep 18, 2022

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants