pydicom / pynetdicom

A Python implementation of the DICOM networking protocol
https://pydicom.github.io/pynetdicom
MIT License
500 stars 176 forks source link

DUL service-user : UnicodeDecodeError #963

Open PankajSujyot opened 1 month ago

PankajSujyot commented 1 month ago

I got following log and error while communicating Sonography machine

D: storescp.py v0.6.0
D:
E: 'ascii' codec can't decode byte 0xc0 in position 0: ordinal not in range(128)
Traceback (most recent call last):
  File "C:\Users\DR SAWALE SIR\AppData\Local\Programs\Python\Python312\Lib\site-packages\pynetdicom\utils.py", line 50, in decode_bytes
    return encoded_value.decode("ascii", errors="strict")
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc0 in position 0: ordinal not in range(128)
E: Unable to decode the received PDU data
E: Unable to decode 'C0 B3 60 49 FC 7F 20 20 20 20 20 20 20 20 20 20' using the ascii codec(s)
Traceback (most recent call last):
  File "C:\Users\DR SAWALE SIR\AppData\Local\Programs\Python\Python312\Lib\site-packages\pynetdicom\dul.py", line 321, in _read_pdu_data
    pdu, event = self._decode_pdu(bytestream)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\DR SAWALE SIR\AppData\Local\Programs\Python\Python312\Lib\site-packages\pynetdicom\dul.py", line 135, in _decode_pdu
    pdu.decode(b)
  File "C:\Users\DR SAWALE SIR\AppData\Local\Programs\Python\Python312\Lib\site-packages\pynetdicom\pdu.py", line 117, in decode
    setattr(self, attr_name, func(bytestream[sl], *args))
  File "C:\Users\DR SAWALE SIR\AppData\Local\Programs\Python\Python312\Lib\site-packages\pynetdicom\pdu.py", line 596, in calling_ae_title
    value = decode_bytes(value).strip()
            ^^^^^^^^^^^^^^^^^^^
  File "C:\Users\DR SAWALE SIR\AppData\Local\Programs\Python\Python312\Lib\site-packages\pynetdicom\utils.py", line 68, in decode_bytes
    raise ValueError(
ValueError: Unable to decode 'C0 B3 60 49 FC 7F 20 20 20 20 20 20 20 20 20 20' using the ascii codec(s)
D: Abort Parameters:
D: =========================== OUTGOING A-ABORT PDU ===========================
D: Abort Source: DUL service-user
D: Abort Reason: (no value available)
D: ============================= END A-ABORT PDU ==============================
E: 'ascii' codec can't decode byte 0xc0 in position 0: ordinal not in range(128)
Traceback (most recent call last):
  File "C:\Users\DR SAWALE SIR\AppData\Local\Programs\Python\Python312\Lib\site-packages\pynetdicom\utils.py", line 50, in decode_bytes
    return encoded_value.decode("ascii", errors="strict")
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc0 in position 0: ordinal not in range(128)
E: Unable to decode the received PDU data
E: Unable to decode 'C0 B3 60 49 FC 7F 20 20 20 20 20 20 20 20 20 20' using the ascii codec(s)
Traceback (most recent call last):
  File "C:\Users\DR SAWALE SIR\AppData\Local\Programs\Python\Python312\Lib\site-packages\pynetdicom\dul.py", line 321, in _read_pdu_data
    pdu, event = self._decode_pdu(bytestream)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\DR SAWALE SIR\AppData\Local\Programs\Python\Python312\Lib\site-packages\pynetdicom\dul.py", line 135, in _decode_pdu
    pdu.decode(b)
  File "C:\Users\DR SAWALE SIR\AppData\Local\Programs\Python\Python312\Lib\site-packages\pynetdicom\pdu.py", line 117, in decode
    setattr(self, attr_name, func(bytestream[sl], *args))
  File "C:\Users\DR SAWALE SIR\AppData\Local\Programs\Python\Python312\Lib\site-packages\pynetdicom\pdu.py", line 596, in calling_ae_title
    value = decode_bytes(value).strip()
            ^^^^^^^^^^^^^^^^^^^
  File "C:\Users\DR SAWALE SIR\AppData\Local\Programs\Python\Python312\Lib\site-packages\pynetdicom\utils.py", line 68, in decode_bytes
    raise ValueError(
ValueError: Unable to decode 'C0 B3 60 49 FC 7F 20 20 20 20 20 20 20 20 20 20' using the ascii codec(s)
D: Abort Parameters:
D: =========================== OUTGOING A-ABORT PDU ===========================
D: Abort Source: DUL service-user
D: Abort Reason: (no value available)
D: ============================= END A-ABORT PDU ==============================
E: 'ascii' codec can't decode byte 0xc0 in position 0: ordinal not in range(128)
Traceback (most recent call last):
  File "C:\Users\DR SAWALE SIR\AppData\Local\Programs\Python\Python312\Lib\site-packages\pynetdicom\utils.py", line 50, in decode_bytes
    return encoded_value.decode("ascii", errors="strict")
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc0 in position 0: ordinal not in range(128)
E: Unable to decode the received PDU data
E: Unable to decode 'C0 B3 60 49 FC 7F 20 20 20 20 20 20 20 20 20 20' using the ascii codec(s)
Traceback (most recent call last):
  File "C:\Users\DR SAWALE SIR\AppData\Local\Programs\Python\Python312\Lib\site-packages\pynetdicom\dul.py", line 321, in _read_pdu_data
    pdu, event = self._decode_pdu(bytestream)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\DR SAWALE SIR\AppData\Local\Programs\Python\Python312\Lib\site-packages\pynetdicom\dul.py", line 135, in _decode_pdu
    pdu.decode(b)
  File "C:\Users\DR SAWALE SIR\AppData\Local\Programs\Python\Python312\Lib\site-packages\pynetdicom\pdu.py", line 117, in decode
    setattr(self, attr_name, func(bytestream[sl], *args))
  File "C:\Users\DR SAWALE SIR\AppData\Local\Programs\Python\Python312\Lib\site-packages\pynetdicom\pdu.py", line 596, in calling_ae_title
    value = decode_bytes(value).strip()
            ^^^^^^^^^^^^^^^^^^^
  File "C:\Users\DR SAWALE SIR\AppData\Local\Programs\Python\Python312\Lib\site-packages\pynetdicom\utils.py", line 68, in decode_bytes
    raise ValueError(
ValueError: Unable to decode 'C0 B3 60 49 FC 7F 20 20 20 20 20 20 20 20 20 20' using the ascii codec(s)
D: Abort Parameters:
D: =========================== OUTGOING A-ABORT PDU ===========================
D: Abort Source: DUL service-user
D: Abort Reason: (no value available)
D: ============================= END A-ABORT PDU ==============================
E: 'ascii' codec can't decode byte 0xc0 in position 0: ordinal not in range(128)
Traceback (most recent call last):
  File "C:\Users\DR SAWALE SIR\AppData\Local\Programs\Python\Python312\Lib\site-packages\pynetdicom\utils.py", line 50, in decode_bytes
    return encoded_value.decode("ascii", errors="strict")
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc0 in position 0: ordinal not in range(128)
E: Unable to decode the received PDU data
E: Unable to decode 'C0 B3 60 49 FC 7F 20 20 20 20 20 20 20 20 20 20' using the ascii codec(s)
Traceback (most recent call last):
  File "C:\Users\DR SAWALE SIR\AppData\Local\Programs\Python\Python312\Lib\site-packages\pynetdicom\dul.py", line 321, in _read_pdu_data
    pdu, event = self._decode_pdu(bytestream)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\DR SAWALE SIR\AppData\Local\Programs\Python\Python312\Lib\site-packages\pynetdicom\dul.py", line 135, in _decode_pdu
    pdu.decode(b)
  File "C:\Users\DR SAWALE SIR\AppData\Local\Programs\Python\Python312\Lib\site-packages\pynetdicom\pdu.py", line 117, in decode
    setattr(self, attr_name, func(bytestream[sl], *args))
  File "C:\Users\DR SAWALE SIR\AppData\Local\Programs\Python\Python312\Lib\site-packages\pynetdicom\pdu.py", line 596, in calling_ae_title
    value = decode_bytes(value).strip()
            ^^^^^^^^^^^^^^^^^^^
  File "C:\Users\DR SAWALE SIR\AppData\Local\Programs\Python\Python312\Lib\site-packages\pynetdicom\utils.py", line 68, in decode_bytes
    raise ValueError(
ValueError: Unable to decode 'C0 B3 60 49 FC 7F 20 20 20 20 20 20 20 20 20 20' using the ascii codec(s)
D: Abort Parameters:
D: =========================== OUTGOING A-ABORT PDU ===========================
D: Abort Source: DUL service-user
D: Abort Reason: (no value available)
D: ============================= END A-ABORT PDU ==============================
E: 'ascii' codec can't decode byte 0xc0 in position 0: ordinal not in range(128)
Traceback (most recent call last):
  File "C:\Users\DR SAWALE SIR\AppData\Local\Programs\Python\Python312\Lib\site-packages\pynetdicom\utils.py", line 50, in decode_bytes
    return encoded_value.decode("ascii", errors="strict")
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc0 in position 0: ordinal not in range(128)
E: Unable to decode the received PDU data
E: Unable to decode 'C0 B3 60 49 FC 7F 20 20 20 20 20 20 20 20 20 20' using the ascii codec(s)
Traceback (most recent call last):
  File "C:\Users\DR SAWALE SIR\AppData\Local\Programs\Python\Python312\Lib\site-packages\pynetdicom\dul.py", line 321, in _read_pdu_data
    pdu, event = self._decode_pdu(bytestream)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\DR SAWALE SIR\AppData\Local\Programs\Python\Python312\Lib\site-packages\pynetdicom\dul.py", line 135, in _decode_pdu
    pdu.decode(b)
  File "C:\Users\DR SAWALE SIR\AppData\Local\Programs\Python\Python312\Lib\site-packages\pynetdicom\pdu.py", line 117, in decode
    setattr(self, attr_name, func(bytestream[sl], *args))
  File "C:\Users\DR SAWALE SIR\AppData\Local\Programs\Python\Python312\Lib\site-packages\pynetdicom\pdu.py", line 596, in calling_ae_title
    value = decode_bytes(value).strip()
            ^^^^^^^^^^^^^^^^^^^
  File "C:\Users\DR SAWALE SIR\AppData\Local\Programs\Python\Python312\Lib\site-packages\pynetdicom\utils.py", line 68, in decode_bytes
    raise ValueError(
ValueError: Unable to decode 'C0 B3 60 49 FC 7F 20 20 20 20 20 20 20 20 20 20' using the ascii codec(s)
D: Abort Parameters:
D: =========================== OUTGOING A-ABORT PDU ===========================
D: Abort Source: DUL service-user
D: Abort Reason: (no value available)
D: ============================= END A-ABORT PDU ==============================
E: 'ascii' codec can't decode byte 0xc0 in position 0: ordinal not in range(128)
Traceback (most recent call last):
  File "C:\Users\DR SAWALE SIR\AppData\Local\Programs\Python\Python312\Lib\site-packages\pynetdicom\utils.py", line 50, in decode_bytes
    return encoded_value.decode("ascii", errors="strict")
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc0 in position 0: ordinal not in range(128)
E: Unable to decode the received PDU data
E: Unable to decode 'C0 B3 60 49 FC 7F 20 20 20 20 20 20 20 20 20 20' using the ascii codec(s)
Traceback (most recent call last):
  File "C:\Users\DR SAWALE SIR\AppData\Local\Programs\Python\Python312\Lib\site-packages\pynetdicom\dul.py", line 321, in _read_pdu_data
    pdu, event = self._decode_pdu(bytestream)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\DR SAWALE SIR\AppData\Local\Programs\Python\Python312\Lib\site-packages\pynetdicom\dul.py", line 135, in _decode_pdu
    pdu.decode(b)
  File "C:\Users\DR SAWALE SIR\AppData\Local\Programs\Python\Python312\Lib\site-packages\pynetdicom\pdu.py", line 117, in decode
    setattr(self, attr_name, func(bytestream[sl], *args))
  File "C:\Users\DR SAWALE SIR\AppData\Local\Programs\Python\Python312\Lib\site-packages\pynetdicom\pdu.py", line 596, in calling_ae_title
    value = decode_bytes(value).strip()
            ^^^^^^^^^^^^^^^^^^^
  File "C:\Users\DR SAWALE SIR\AppData\Local\Programs\Python\Python312\Lib\site-packages\pynetdicom\utils.py", line 68, in decode_bytes
    raise ValueError(
ValueError: Unable to decode 'C0 B3 60 49 FC 7F 20 20 20 20 20 20 20 20 20 20' using the ascii codec(s)
D: Abort Parameters:
D: =========================== OUTGOING A-ABORT PDU ===========================
D: Abort Source: DUL service-user
D: Abort Reason: (no value available)
D: ============================= END A-ABORT PDU ==============================
E: 'ascii' codec can't decode byte 0xc0 in position 0: ordinal not in range(128)
Traceback (most recent call last):
  File "C:\Users\DR SAWALE SIR\AppData\Local\Programs\Python\Python312\Lib\site-packages\pynetdicom\utils.py", line 50, in decode_bytes
    return encoded_value.decode("ascii", errors="strict")
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc0 in position 0: ordinal not in range(128)
E: Unable to decode the received PDU data
E: Unable to decode 'C0 B3 60 49 FC 7F 20 20 20 20 20 20 20 20 20 20' using the ascii codec(s)
Traceback (most recent call last):
  File "C:\Users\DR SAWALE SIR\AppData\Local\Programs\Python\Python312\Lib\site-packages\pynetdicom\dul.py", line 321, in _read_pdu_data
    pdu, event = self._decode_pdu(bytestream)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\DR SAWALE SIR\AppData\Local\Programs\Python\Python312\Lib\site-packages\pynetdicom\dul.py", line 135, in _decode_pdu
    pdu.decode(b)
  File "C:\Users\DR SAWALE SIR\AppData\Local\Programs\Python\Python312\Lib\site-packages\pynetdicom\pdu.py", line 117, in decode
    setattr(self, attr_name, func(bytestream[sl], *args))
  File "C:\Users\DR SAWALE SIR\AppData\Local\Programs\Python\Python312\Lib\site-packages\pynetdicom\pdu.py", line 596, in calling_ae_title
    value = decode_bytes(value).strip()
            ^^^^^^^^^^^^^^^^^^^
  File "C:\Users\DR SAWALE SIR\AppData\Local\Programs\Python\Python312\Lib\site-packages\pynetdicom\utils.py", line 68, in decode_bytes
    raise ValueError(
ValueError: Unable to decode 'C0 B3 60 49 FC 7F 20 20 20 20 20 20 20 20 20 20' using the ascii codec(s)
D: Abort Parameters:
D: =========================== OUTGOING A-ABORT PDU ===========================
D: Abort Source: DUL service-user
D: Abort Reason: (no value available)
D: ============================= END A-ABORT PDU ==============================
E: 'ascii' codec can't decode byte 0xc0 in position 0: ordinal not in range(128)
Traceback (most recent call last):
  File "C:\Users\DR SAWALE SIR\AppData\Local\Programs\Python\Python312\Lib\site-packages\pynetdicom\utils.py", line 50, in decode_bytes
    return encoded_value.decode("ascii", errors="strict")
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc0 in position 0: ordinal not in range(128)
E: Unable to decode the received PDU data
E: Unable to decode 'C0 B3 60 49 FC 7F 20 20 20 20 20 20 20 20 20 20' using the ascii codec(s)
Traceback (most recent call last):
  File "C:\Users\DR SAWALE SIR\AppData\Local\Programs\Python\Python312\Lib\site-packages\pynetdicom\dul.py", line 321, in _read_pdu_data
    pdu, event = self._decode_pdu(bytestream)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\DR SAWALE SIR\AppData\Local\Programs\Python\Python312\Lib\site-packages\pynetdicom\dul.py", line 135, in _decode_pdu
    pdu.decode(b)
  File "C:\Users\DR SAWALE SIR\AppData\Local\Programs\Python\Python312\Lib\site-packages\pynetdicom\pdu.py", line 117, in decode
    setattr(self, attr_name, func(bytestream[sl], *args))
  File "C:\Users\DR SAWALE SIR\AppData\Local\Programs\Python\Python312\Lib\site-packages\pynetdicom\pdu.py", line 596, in calling_ae_title
    value = decode_bytes(value).strip()
            ^^^^^^^^^^^^^^^^^^^
  File "C:\Users\DR SAWALE SIR\AppData\Local\Programs\Python\Python312\Lib\site-packages\pynetdicom\utils.py", line 68, in decode_bytes
    raise ValueError(
ValueError: Unable to decode 'C0 B3 60 49 FC 7F 20 20 20 20 20 20 20 20 20 20' using the ascii codec(s)
D: Abort Parameters:
D: =========================== OUTGOING A-ABORT PDU ===========================
D: Abort Source: DUL service-user
D: Abort Reason: (no value available)
D: ============================= END A-ABORT PDU ==============================
scaramallion commented 1 month ago

The sonography machine is non-conformant to the DICOM Standard as ASCII is required for that value, which I'm guessing is probably the AE title. It's using a different codec, but you'd know better than I would which codec is most likely (UTF16 worked for me, but I don't know if the result is valid). You can use _config.CODECS to customise the codecs used to decode values.

If you have control over the sonography unit then I'd strongly recommend using a conformant ASCII value.