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
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 14: ordinal not in range(128) #560
Comments
And the Dockerfile for the container where this is run:
|
Why have you done Anyway, it seems like whatever you're associating with is using non-conformant UIDs (they're supposed to be encoded as ASCII). Could you bind the following to from pydicom.utils import pretty_bytes
def debug_data(event):
data = event.data
LOGGER.debug(f"{' DEBUG - ENCODED PDU ':=^76}")
slist = pretty_bytes(
data, prefix=' ', delimiter=' ', max_size=None, items_per_line=25
)
for s in slist:
LOGGER.debug(s)
LOGGER.debug(f"{' END ENCODED PDU ':=^76}")
handlers = [(evt.EVT_C_STORE, handle_store), (evt.EVT_DATA_RECV, debug_data)] |
Thank You for your help! Fixed that event-dataset, it was a part of my uninformed debugging. The code I run now is this:
And it gives me this after I send an MRI image using OsiriX a to it:
|
Yeah, there are two presentation contexts containing UIDs that aren't encoded in ASCII: >>> raw = (
... b"\x31\x2e\x32\x2e\x38\x34\x30\x2e\x31\x30\x30\x30\x38"
... b"\x2e\xe2\x80\x8b\x35\x2e\xe2\x80\x8b\x31\x2e\xe2\x80\x8b\x34\x2e\xe2\x80\x8b\x31\x2e\xe2\x80\x8b\x31"
... b"\x2e\xe2\x80\x8b\x31\x30\x34\x2e\xe2\x80\x8b\x33"
... )
>>> raw.decode('ascii')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 14: ordinal not in range(128)
>>> raw.decode('utf-8')
'1.2.840.10008.5.1.4.1.1.104.3'
|
Ok, good to know! This is odd, it is just normal clinical dicom images. Any hints how I should fix this? |
The two non-conformant presentation contexts both have an invalid '1.2.840.10008.5.1.4.1.1.104.3', which should be Encapsulated STL Storage. I'd take a look in the configuration for Osirix and make sure the entry there is in ASCII rather than UTF-8 (they'll look identical, but if you copy the UID in ASCII and use it to overwrite the value maybe it'll fix it?). Alternatively you could just remove Encapsulated STL Storage from the config, provided you don't need it. It'd be nice to let Osirix know about the issue, but from a brief googling it looks like you need to pay for the privilege 🙄 I'm trying to decide if I should add UTF-8 decoding as a fallback... in the meantime I think you can do the following as a workaround (should be done before importing anything else): from pydicom.uid import UID
from pynetdicom.pdu_items import AbstractSyntaxSubItem
from pynetdicom.utils import validate_uid
def my_setter(self, value):
if isinstance(value, UID):
pass
elif isinstance(value, str):
value = UID(value)
elif isinstance(value, bytes):
try:
value = UID(value.decode('ascii'))
except UnicodeDecodeError:
value = UID(value.decode('utf-8'))
elif value is None:
pass
else:
raise TypeError(
'Abstract Syntax Name must be a pydicom.uid.UID, str or bytes'
)
if value is not None and not validate_uid(value):
LOGGER.error("Abstract Syntax Name is an invalid UID")
raise ValueError("Abstract Syntax Name is an invalid UID")
self._abstract_syntax_name = value
AbstractSyntaxSubItem.abstract_syntax_name = AbstractSyntaxSubItem.abstract_syntax_name.setter(my_setter)
from pynetdicom import pdu
pdu.AbstractSyntaxSubItem = AbstractSyntaxSubItem
from pynetdicom import AE
# ... etc |
@mijuny I know this has been closed for a while now but I recently encountered the same issue with Osirix and it seems like there is still no fix/way around. This solution here works fine but would require me to change the pynetdicom code. So I was wondering if you ever found another solution maybe within Osirix? |
Hi! I'm not aware if any other solution. For me, this simple and crude node is working with OsiriX:
Running this in this conda env in macOS:
|
For anyone else, the easier way to workaround this issue is by setting the _config.CODECS variable to include UTF-8. Or pester Osirix for a fix. |
Hi!
I'm getting the error above when running a simple pynetdicom storage SCP.
I'm a bit new to python so it is sure to be a simple thing. Have been googling around for a while now without luck. Any help would really welcome!
And the error:
The text was updated successfully, but these errors were encountered: