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
Error : a bytes-like object is required, not 'MultiValue' #1412
Comments
Also tried following code to get the byte string, but same error.
|
O* VRs should be Also, in the future if have an issue it's much more helpful if you post the full traceback rather than the error since we can look at it to figure out where in the code the exception is occurring. It would also help if you posted the version of Python you're using. This works fine for me with Python 3.9 and pydicom 2.1.2: from pydicom import Dataset
import array
arr = array.array('H', range(10))
ds = Dataset()
ds.is_little_endian = True
ds.is_implicit_VR = False
ds.LongTrianglePointIndexList = arr.tobytes()
print(ds["LongTrianglePointIndexList"].VR) # 'OL'
ds.save_as('temp.dcm') This also works fine: ds = Dataset()
ds.add_new(0x00660040, 'OL', arr.tobytes()) |
Thank you for the answer. One more information is that the 'ds' is actually read from a file in the disk (ds=pydicom.read_file(filename)). pydicom - 2.0.0.0 Thank you. |
Could you post a minimal code sample that reproduces the issue please? If you're using something like this: Then you're missing the |
Hello, Please find the actual code used below, import pydicom
from pydicom.sequence import Sequence
from pydicom.dataelem import DataElement
from pydicom.dataset import Dataset
ds = pydicom.read_file(filename)
surfaceSeq= ds[0x0066,0x0002]
#// read existing sequence items in the dataset
seqlist=[]
for n in surfaceSeq:
seqlist.append(n)
newDs = Dataset()
surfaceMeshPrimitiveSq = Dataset()
lineSeq = Dataset()
indexData = list(range(1,100))
indexData = array.array('H', indexData)
indexData = indexData.tobytes()
lineSeq.add_new(0x00660040, 'OL', indexData)
surfaceMeshPrimitiveSq.add_new(0x00660028, 'SQ', [lineSeq])
newDs.add_new(0x00660013, 'SQ', [surfaceMeshPrimitiveSq])
#add the new sequnce item to the list
seqlist.append(newDs)
ds[0x0066,0x0002] = DataElement(0x00660002,"SQ",seqlist)
ds.save_as(filename) |
OK, I can reproduce with: import array
from pydicom import Dataset
from pydicom.uid import ExplicitVRLittleEndian
ds = Dataset()
ds.file_meta = Dataset()
ds.file_meta.TransferSyntaxUID = ExplicitVRLittleEndian
b = array.array('H', range(100)).tobytes()
ds.LongPrimitivePointIndexList = b
ds.save_as('1421.dcm') And
I think this is because the byte value is hitting the hex for the backslash character during assignment. Ouch, that's kinda nasty. |
As a workaround you can do the equivalent of: b = array.array('H', range(100)).tobytes()
ds.LongPrimitivePointIndexList = None
# Bypass the value check and set it directly
ds["LongPrimitivePointIndexList"]._value = b The problem arises because elements with a VR of OL (and OD and OV) aren't being excluded from the backslash check. Thanks, we'll have a fix in for the next release. |
Thank you. |
We really should have a checklist or something for what needs to be changed when we add new VRs... |
Hello,
I am getting following error while updating the tag LongTrianglePointIndexList (0066,0040),
TypeError: a bytes-like object is required, not 'MultiValue'
I noticed that the error gets produced only when the VR is given as "OL" , works fine with "OB", "OF" etc.
sample code (assume 'lineSeq' is the dicom dataset sequence):
outcome: TypeError: a bytes-like object is required, not 'MultiValue'
using version - 2.0.0.0
Any help is appreciated.
Thank you
The text was updated successfully, but these errors were encountered: