title: python can read image file to binary
body: <p>i need to upload a image file, and i use MultipartPostHandler.py as people suggest.
  but still doesn't work.
  here is my code:</p>
  
  <pre><code>params = {"upload", open("12345.jpg", "rb")} // in 'rb'
  opener = urllib2.build_opener(MultipartPostHandler)
  res = opener.open(url, params)
  </code></pre>
  
  <p>and here is the code in MultipartPostHander:</p>
  
  <pre><code>def multipart_encode(vars, files, boundary = None, buffer = None):
      if boundary is None:
          boundary = mimetools.choose_boundary()
      if buffer is None:
          buffer = ''
      for(key, value) in vars:
          buffer += '--%s\r\n' % boundary
          buffer += 'Content-Disposition: form-data; name="%s"' % key
          buffer += '\r\n\r\n' + value + '\r\n'
      for(key, fd) in files:
          file_size = os.fstat(fd.fileno())[stat.ST_SIZE]
          filename = fd.name.split('/')[-1]
          contenttype = mimetypes.guess_type(filename)[0] or 'application/octet-stream'
          buffer += '--%s\r\n' % boundary
          buffer += 'Content-Disposition: form-data; name="%s"; filename="%s"\r\n' % (key, filename)
          buffer += 'Content-Type: %s\r\n' % contenttype
          # buffer += 'Content-Length: %s\r\n' % file_size
          fd.seek(0)
          buffer += '\r\n' + fd.read() + '\r\n'
      buffer += '--%s--\r\n\r\n' % boundary
      return boundary, buffer
  multipart_encode = Callable(multipart_encode)
  
  https_request = http_request
  </code></pre>
  
  <p>and error appears at:</p>
  
  <pre><code>buffer += '\r\n' + fd.read() + '\r\n'
  </code></pre>
  
  <p>error is:</p>
  
  <pre><code>'ascii' codec can't decode byte 0xff in position 2: ordinal not in range(128)
  </code></pre>
  
  <p>this problem scrowed me a lot , please help me out! 
  thx.</p>