Open tanyibo-cnb opened 2 years ago
Does it work if copy the file to the current directory first?
dfs = Dfsu("F0 Q=2230.dfsu")
In DfsFile.py,
change
fnp.value = filename.encode("cp1252")
to
fnp.value = filename.encode("cp936")
it will work.
Because the path name contain chinese character, and the OS is Windows, the filename can't be encoded in cp1252.
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
”“”