code: def _2(self):
          
          boundary = self.boundary
          buf = StringIO()
          for (key, value) in self.form_fields:
              buf.write('--%s\r\n' % boundary)
              buf.write('Content-Disposition: form-data; name="%s"' % key)
              buf.write('\r\n\r\n%s\r\n' % value)
          for (key, filename, mimetype, filepath) in self.files:
              if os.path.isfile(filepath):
                  buf.write('--{boundary}\r\n'
                            'Content-Disposition: form-data; name="{key}"; '
                            'filename="{filename}"\r\n'
                            'Content-Type: {content_type}\r\n\r\n'.format(
                                boundary=boundary,
                                key=key,
                                filename=filename,
                                content_type=mimetype))
                  with open(filepath, "rb") as f:
                      shutil.copyfileobj(f, buf)
                  buf.write('\r\n')
          buf.write('--' + boundary + '--\r\n\r\n')
          buf = buf.getvalue()
          self.form_data = buf
docs: python 2.x version of formatting body data