title: POST binary data using httplib cause Unicode exceptions
body: <p>When i try to send an image with urllib2 the UnicodeDecodeError exception is occured.</p>
  
  <p>HTTP Post body:</p>
  
  
  
  <pre class="lang-python prettyprint-override"><code>f = open(imagepath, "rb")
  binary = f.read()
  mimetype, devnull = mimetypes.guess_type(urllib.pathname2url(imagepath))
  
  body = """Content-Length: {size}
  Content-Type: {mimetype}
  
  {binary}
  """.format(size=os.path.getsize(imagepath),  
             mimetype=mimetype,
             binary=binary)
  
  request = urllib2.Request(url, body, headers)
  opener = urllib2.build_opener(urllib2.HTTPSHandler(debuglevel=1))
  response = opener.open(request)
  print response.read()
  </code></pre>
  
  <p>Traceback :</p>
  
  <pre class="lang-python prettyprint-override"><code>   response = opener.open(request)
    File "/usr/local/lib/python2.7/urllib2.py", line 404, in open
      response = self._open(req, data)
    File "/usr/local/lib/python2.7/urllib2.py", line 422, in _open
      '_open', req)
    File "/usr/local/lib/python2.7/urllib2.py", line 382, in _call_chain
      result = func(*args)
    File "/usr/local/lib/python2.7/urllib2.py", line 1222, in https_open
      return self.do_open(httplib.HTTPSConnection, req)
    File "/usr/local/lib/python2.7/urllib2.py", line 1181, in do_open
      h.request(req.get_method(), req.get_selector(), req.data, headers)
    File "/usr/local/lib/python2.7/httplib.py", line 973, in request
      self._send_request(method, url, body, headers)
    File "/usr/local/lib/python2.7/httplib.py", line 1007, in _send_request
      self.endheaders(body)
    File "/usr/local/lib/python2.7/httplib.py", line 969, in endheaders
      self._send_output(message_body)
    File "/usr/local/lib/python2.7/httplib.py", line 827, in _send_output
      msg += message_body
    File "/home/usertmp/biogeek/lib/python2.7/encodings/utf_8.py", line 16, in decode
      return codecs.utf_8_decode(input, errors, True)
  UnicodeDecodeError: 'utf8' codec can't decode byte 0xff in position 49: invalid start byte
  </code></pre>
  
  <p>python version 2.7.5</p>
  
  <p>Anyone know a solution to this?</p>