equinor / dlisio

Python library for working with the well log formats Digital Log Interchange Standard (DLIS V1) and Log Information Standard (LIS79)
https://dlisio.readthedocs.io/en/latest/
Other
121 stars 39 forks source link

OSError when trying to load filepaths with non-ASCII characters #377

Closed erlendviggen closed 3 years ago

erlendviggen commented 3 years ago

When trying to open a file whose filepath has a non-ASCII character, I get the following error:

---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
<ipython-input-8-b17bf9a0ba47> in <module>
----> 1 dlis.load('path\\to\\file with æøå.dlis')

C:\Appl\Anaconda3\lib\site-packages\dlisio\dlis\load.py in load(path, error_handler)
     71         raise OSError("'{}' is not an existing regular file".format(path))
     72 
---> 73     stream = common.open(path)
     74     tm = core.read_tapemark(stream)
     75     is_tif = core.valid_tapemark(tm)

C:\Appl\Anaconda3\lib\site-packages\dlisio\common\open.py in open(path, offset)
     22     dlisio.lis.load
     23     """
---> 24     return core.open(str(path), offset)

OSError: unable to open file for path path\to\file with æøå.dlis : No such file or directory

This happens for filepaths containing the Norwegian characters æ, ø, or å, so I am assuming it happens for all non-ASCII characters. I am experiencing this on Windows with Python 3.8.8 and dlisio 0.3.4. Accessing the file using basic Python (open('path\\to\\file with æøå.dlis', 'rb')) works without returning any OSErrors, so it looks like this might be a dlisio-specific bug.

I can of course work around the problem by renaming the DLIS files in question to replace these characters, but a fix (or a better workaround!) would be nice to have.

ErlendHaa commented 3 years ago

Hi!

dlisio don't use Python's open. The root cause of this is that on Windows, C++'s std::fopen cannot be called with UTF-8 strings. On all other modern platforms it can. Alena has already drafted a fix for this (#379)

ErlendHaa commented 3 years ago

This is solved in #379. Expect a new release today

erlendviggen commented 3 years ago

I can confirm that version 0.3.5 fixes this issue. Thanks!