'Based on Wade Leftwich\'s function:
http://code.activestate.com/recipes/146306/'

def _encode_multipart_formdata(self, fields):

    boundary = ''
    while (boundary in ''.join(fields)):
        boundary = binascii.hexlify(os.urandom(16)).decode('utf-8')
    L = []
    for i in fields:
        L.append(('--' + boundary))
        L.append(('Content-Disposition:    form-data;    name="%s"' % i))
        L.append('')
        L.append(fields[i])
    L.append((('--' + boundary) + '--'))
    L.append('')
    body = '\r\n'.join(L)
    content_type = ('multipart/form-data;    boundary=%s' % boundary)
    header = {'Content-Type': content_type}
    return (header, body)
