# Buggy code
def __init__(
    self,
    tag,
    VR,
    value,
    file_value_tell=None,
    is_undefined_length=False,
    already_converted=False,
):
    """Create a new DataElement.

    Parameters
    ----------
    tag
        The DICOM (group, element) tag in any form accepted by
        pydicom.tag.Tag such as [0x0010, 0x0010], (0x10, 0x10), 0x00100010,
        etc.
    VR : str
        The 2 character DICOM value representation (see DICOM standard part
        5, Section 6.2).
    value
        The value of the data element. One of the following:
        * a single string value
        * a number
        * a list or tuple with all strings or all numbers
        * a multi-value string with backslash separator
    file_value_tell : int or None
        Used internally by Dataset to store the write position for the
        ReplaceDataElementValue() method. Default is None.
    is_undefined_length : bool
        Used internally to store whether the length field for this element
        was 0xFFFFFFFFL, i.e. 'undefined length'. Default is False.
    already_converted : bool
        Used to determine whether or not `value` requires conversion to a
        value with VM > 1. Default is False.
    """
    if not isinstance(tag, BaseTag):
        tag = Tag(tag)
    self.tag = tag
    self.VR = VR  # Note!: you must set VR before setting value
    if already_converted:
        self._value = value
    else:
        self.value = value  # calls property setter which will convert
    self.file_tell = file_value_tell
    self.is_undefined_length = is_undefined_length


# Traceback (KeyError)
(test) root@DESKTOP-COPUCVT:/mnt/e/test# python3 mydicom.py
Traceback (most recent call last):
File "/root/.local/share/virtualenvs/test-LINKoilU/lib/python3.6/site-packages/pydicom/charset.py", line 625, in convert_encodings
py_encodings.append(python_encoding[encoding])
KeyError: 73

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "mydicom.py", line 12, in <module>
pydicom.dcmread("DX.X.1.2.276.0.7230010.3.1.4.313262848.25.1563878256.444385.dcm")
File "/root/.local/share/virtualenvs/test-LINKoilU/lib/python3.6/site-packages/pydicom/filereader.py", line 850, in dcmread
force=force, specific_tags=specific_tags)
File "/root/.local/share/virtualenvs/test-LINKoilU/lib/python3.6/site-packages/pydicom/filereader.py", line 728, in read_partial
specific_tags=specific_tags)
File "/root/.local/share/virtualenvs/test-LINKoilU/lib/python3.6/site-packages/pydicom/filereader.py", line 382, in read_dataset
encoding = convert_encodings(char_set)
File "/root/.local/share/virtualenvs/test-LINKoilU/lib/python3.6/site-packages/pydicom/charset.py", line 628, in convert_encodings
_python_encoding_for_corrected_encoding(encoding))
File "/root/.local/share/virtualenvs/test-LINKoilU/lib/python3.6/site-packages/pydicom/charset.py", line 647, in _python_encoding_for_corrected_encoding
if re.match('^ISO[^_]IR', encoding) is not None:
File "/root/.local/share/virtualenvs/test-LINKoilU/lib/python3.6/re.py", line 172, in match
return _compile(pattern, flags).match(string)
TypeError: expected string or bytes-like object

# Fixed code
def __init__(
    self,
    tag,
    VR,
    value,
    file_value_tell=None,
    is_undefined_length=False,
    already_converted=False,
):
    """Create a new DataElement.

    Parameters
    ----------
    tag
        The DICOM (group, element) tag in any form accepted by
        pydicom.tag.Tag such as [0x0010, 0x0010], (0x10, 0x10), 0x00100010,
        etc.
    VR : str
        The 2 character DICOM value representation (see DICOM standard part
        5, Section 6.2).
    value
        The value of the data element. One of the following:
        * a single string value
        * a number
        * a list or tuple with all strings or all numbers
        * a multi-value string with backslash separator
    file_value_tell : int or None
        Used internally by Dataset to store the write position for the
        ReplaceDataElementValue() method. Default is None.
    is_undefined_length : bool
        Used internally to store whether the length field for this element
        was 0xFFFFFFFFL, i.e. 'undefined length'. Default is False.
    already_converted : bool
        Used to determine whether or not `value` requires conversion to a
        value with VM > 1. Default is False.
    """
    if not isinstance(tag, BaseTag):
        tag = Tag(tag)
    self.tag = tag

    # a known tag shall only have the VR 'UN' if it has a length that
    # exceeds the size that can be encoded in 16 bit - all other cases
    # can be seen as an encoding error and can be corrected
    if VR == "UN" and (is_undefined_length or value is None or len(value) < 0xFFFF):
        try:
            VR = dictionary_VR(tag)
        except KeyError:
            pass

    self.VR = VR  # Note!: you must set VR before setting value
    if already_converted:
        self._value = value
    else:
        self.value = value  # calls property setter which will convert
    self.file_tell = file_value_tell
    self.is_undefined_length = is_undefined_length