title: How do I fix pydicom's dcmread() preamble error?
body: <p>I am having trouble with <code>dcmread()</code> on a DICOM file that does exists at given path. I'm not sure what went wrong. Here is my code:</p>
  <pre><code>import pydicom
  
  f = &quot;/exact/path/hi.dcm&quot;
  fn = get_testdata_file(f)
  ds = pydicom.dcmread(fn)
  
  ds.SOPClassUID = ds.MediaStorageSOPClassUID
  </code></pre>
  <p>I am getting below error:</p>
  <pre><code>Traceback (most recent call last):
    File &quot;addfields.py&quot;, line 14, in &lt;module&gt;
      ds = pydicom.dcmread(fn)
    File &quot;/Users/user/opt/anaconda3/lib/python3.7/site-packages/pydicom/filereader.py&quot;, line 871, in dcmread
      force=force, specific_tags=specific_tags)
    File &quot;/Users/user/opt/anaconda3/lib/python3.7/site-packages/pydicom/filereader.py&quot;, line 668, in read_partial
      preamble = read_preamble(fileobj, force)
    File &quot;/Users/user/opt/anaconda3/lib/python3.7/site-packages/pydicom/filereader.py&quot;, line 605, in read_preamble
      preamble = fp.read(128)
  AttributeError: 'NoneType' object has no attribute 'read'
  </code></pre>
  <p>But I am not sure why, because &quot;hi.dcm&quot; is a file that exists (path is correct) and has metadata inside. I do not know what is preamble and whether it present in the image I am dealing with.</p>