title: Why do I get a TypeError when passing a bytes string to magic.from_buffer()?
body: <p>I am trying to get the filetype of an image from the url using python-magic's <code>from_buffer</code>, and it works well in practice, but fails when I try to run a unittest.</p>
  
  <p>This is my function:</p>
  
  <pre><code>def get_uri_from_url(url):
      if url != '':
          response = requests.get(url)
          data_type = magic.from_buffer(response.content, mime=True)
          image_bytes = str(base64.b64encode(response.content).decode('utf-8'))
          return f'data:{data_type};base64,{image_bytes}'
      return url
  </code></pre>
  
  <p>And this is the test so far:</p>
  
  <pre><code>    def test_get_uri_from_url(self):
          test_bytes = b'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x05\x00\x00\x00\x05\x08\x06\x00\x00\x00\x8do&amp;' \
                       b'\xe5\x00\x00\x00\x1cIDAT\x08\xd7c\xf8\xff\xff?\xc3\x7f\x06 \x05\xc3 \x12\x84\xd01\xf1\x82X\xcd' \
                       b'\x04\x00\x0e\xf55\xcb\xd1\x8e\x0e\x1f\x00\x00\x00\x00IEND\xaeB`\x82'
  
          class Requests:
              content = test_bytes
  
              def get(self, url):
                  return self
  
          with patch('path_to_my_function.requests', return_value=Requests):
              self.assertEqual(
                  get_uri_from_url('any_url'),
                  f'data:image/png;base64,{test_bytes}'
              )
  </code></pre>
  
  <p>This test takes ages to run, and finally errors with the following traceback:</p>
  
  <pre><code>Traceback (most recent call last):
    File "/&lt;path&gt;/test_file.py", line 90, in test_get_uri_from_url
      get_uri_from_url('any_url'),
    File "/&lt;path&gt;/file.py", line 165, in get_uri_from_url
      data_type = magic.from_buffer(response.content, mime=True)
    File "/&lt;path_to_python&gt;/python3.6/site-packages/magic.py", line 148, in from_buffer
      return m.from_buffer(buffer)
    File "/&lt;path_to_python&gt;/python3.6/site-packages/magic.py", line 80, in from_buffer
      return maybe_decode(magic_buffer(self.cookie, buf))
    File "/&lt;path_to_python&gt;/python3.6/site-packages/magic.py", line 255, in magic_buffer
      return _magic_buffer(cookie, buf, len(buf))
  ctypes.ArgumentError: argument 2: &lt;class 'TypeError'&gt;: wrong type
  </code></pre>
  
  <p>I can't see what I'm doing wrong, when I run this in a terminal it works fine, I must be missing something.</p>
  
  <pre><code>In [17]: response = requests.get('https://upload.wikimedia.org/wikipedia/commons/3/31/Red-dot-5px.png')                                                                           
  
  In [18]: response.content                                                                                                                                                         
  Out[18]: b'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x05\x00\x00\x00\x05\x08\x06\x00\x00\x00\x8do&amp;\xe5\x00\x00\x00\x1cIDAT\x08\xd7c\xf8\xff\xff?\xc3\x7f\x06 \x05\xc3 \x12\x84\xd01\xf1\x82X\xcd\x04\x00\x0e\xf55\xcb\xd1\x8e\x0e\x1f\x00\x00\x00\x00IEND\xaeB`\x82'
  
  In [19]: magic.from_buffer(response.content, mime=True)                                                                                                                           
  Out[19]: 'image/png'
  </code></pre>