title: Python: Save a hex string to a jpg image file
body: <p>I have multiple hex strings like this one (big string so I truncated the middle):</p>
  
  <blockquote>
    <p>0xFFD8FFEE000E41646F626500640000000002FFE11E2445786966000049492A006A0500002C010000010000002C0100000100000041646F62652050686F746F73686F702043533620284D6163................................................................................................................................................................7D8D9DAE1E2E3E4E5E6E7E8E9EAF1F2F3FF7F8F9FAFFC4001F0100030101010101010101010000000000000102030405060708090A0BFFC400B511000201020404030407050404000102770</p>
  </blockquote>
  
  <p>I want to save each string in a file. But my code is not working well:</p>
  
  <pre><code>import binascii
  
  data = binascii.a2b_hex(my_hex_string)
  with open('/path/image.jpg', 'wb') as image_file:
      image_file.write(data)
  </code></pre>
  
  <p>I receive this error:</p>
  
  <blockquote>
    <p>TypeError: Odd-length string</p>
  </blockquote>
  
  <p>When I remove the first <code>0</code> I get this:</p>
  
  <blockquote>
    <p>TypeError: Non-hexadecimal digit found</p>
  </blockquote>
  
  <p>When I remove the two first chars (since JPG is supposed to start with FF D8), I get this again:</p>
  
  <blockquote>
    <p>TypeError: Odd-length string</p>
  </blockquote>
  
  <p>Any ideas please?</p>