title: Python throw UnicodeDecodeError
body: <p>I am using python 2.6, and from what I read, reading a binary file will result in string, but I am unable to concatenante the string with a B"\r\n" string. I have searched but most result are concatenating UTF string while my case is concatenating binary with string</p>
  
  <p>Below codes work fine until the line body = "\r\n".join(lines), supposely lines are list that has both normal ASCII string and also Binary content read from file, when joining them together throws UnicodeDecodeError, how do I join a binary data with a string? below code is for uploading a file to web.</p>
  
  <pre><code>        def get_content_type (filename):
              return mimetypes.guess_type(filename)[0] or 'application/octet-stream'
  
          def encode_field (field_name):
              return ('--' + boundary,
                      'Content-Disposition: form-data; name="%s"' % field_name,
                      '', str (data [field_name]))
  
          def encode_file (field_name):
              filename = files[field_name]
              return ('--' + boundary,
                      'Content-Disposition: form-data; name="%s"; filename="%s"' % (field_name, StringOps.GetFilename(filename)),
                      'Content-Type: %s' % get_content_type(filename),
                      '', open(filename, 'rb').read())
  
          lines = []
          if (data):
              for name in data:
                 lines.extend(encode_field(name))
  
          for name in files:
              lines.extend(encode_file(name))
  
          lines.extend(('--%s--' % boundary, ''))
          #BELOW THROWS EXCEPTION
          body = "\r\n".join(lines)
          #UnicodeDecodeError, something like that
          print "Baa"
  </code></pre>
  
  <p>Below some sample I made up</p>
  
  <pre><code>data = []
  data.append(open("1.mkv", 'rb').read())
  data.append("somestring")
  
  body = "\r\n".join(data)
  #throws exception
  </code></pre>