title: Querying binary values in Python from SQL server
body: <p>I'm executing this query</p>
  
  <pre><code>SELECT CMDB_ID FROM DB1.[dbo].[CDMID]
  </code></pre>
  
  <p>when I do this on SSMS 18 I get this:</p>
  
  <p><a href="https://i.stack.imgur.com/OHSoh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/OHSoh.png" alt="enter image description here"></a></p>
  
  <p>I'm aware these are HEX values, although I'm not an expert on the topic.</p>
  
  <p>I need to excute this exact query on python so I can process that information through a script, this script need as input the HEX values without any manipulation (as you see in the SSMS output).</p>
  
  <p>So, through <code>pyodbc</code> library with a regular connection:</p>
  
  <pre><code>SQLserver_Connection("Driver={SQL Server Native Client 11.0};"
                       "Server=INSTANCE;"
                       "Database=DB1;"
                       "UID=USER;"
                       "PWD=PASS;")
  </code></pre>
  
  <p>I get this:</p>
  
  <pre><code>0   b'@\x12\x90\xb2\xbb\x92\xbbe\xa3\xf9:\xe2\x97@...
  1   b'@"\xaf\x13\x18\xc9}\xc6\xb0\xd4\x87\xbf\x9e\...
  2   b'@G\xc5rLh5\x1c\xb8h\xe0\xf0\xe4t\x08\xbb'
  3   b'@\x9f\xe65\xf8tR\xda\x85S\xdcu\xd3\xf6*\xa2'
  4   b'@\xa4\xcb^T\x06\xb2\xd0\x91S\x9e\xc0\xa7\xe543'
  ... ...
  122 b'O\xa6\xe1\xd8\tA\xe9E\xa0\xf7\x96\x7f!"\xa3\...
  123 b'O\xa9j,\x02\x89pF\xb9\xb4:G]y\xc4\xb6'
  124 b'O\xab\xb6gy\xa2\x17\x1b\xadd\xc3\r\xa6\xee50'
  125 b'O\xd7ogpWj\xee\xb0\xd8!y\xec\x08\xc7\xfa'
  126 b"O\xf0u\x14\xcd\x8cT\x06\x9bm\xea\xddY\x08'\xef"
  </code></pre>
  
  <p>I have three questions:</p>
  
  <ol>
  <li>How can this data be intepreted, why am I getting this?</li>
  <li>Is there a way to manipulate this data back at the original HEX value? and if not...</li>
  <li>What can I do to receive the original HEX value?</li>
  </ol>
  
  <p>I've looking for a solution but haven't found anything yet, as you can see I'm not an expert on this kind of topics so if you are not able to provide a solution I will, also, really appreciate documents with some background knowledge that I need to get so I can provide a solution by myself.</p>