ytdl-org/youtube-dl · error · ValueError

Boundary overlaps with data

Error message

Boundary overlaps with data

What it means

Error "Boundary overlaps with data" thrown in ytdl-org/youtube-dl.

Source

Thrown at youtube_dl/utils.py:4352

        origin_req_host=req.origin_req_host, unverifiable=req.unverifiable)
    if hasattr(req, 'timeout'):
        new_req.timeout = req.timeout
    return new_req


def _multipart_encode_impl(data, boundary):
    content_type = 'multipart/form-data; boundary=%s' % boundary

    out = b''
    for k, v in data.items():
        out += b'--' + boundary.encode('ascii') + b'\r\n'
        k = _encode_compat_str(k, 'utf-8')
        v = _encode_compat_str(v, 'utf-8')
        # RFC 2047 requires non-ASCII field names to be encoded, while RFC 7578
        # suggests sending UTF-8 directly. Firefox sends UTF-8, too
        content = b'Content-Disposition: form-data; name="' + k + b'"\r\n\r\n' + v + b'\r\n'
        if boundary.encode('ascii') in content:
            raise ValueError('Boundary overlaps with data')
        out += content

    out += b'--' + boundary.encode('ascii') + b'--\r\n'

    return out, content_type


def multipart_encode(data, boundary=None):
    '''
    Encode a dict to RFC 7578-compliant form-data

    data:
        A dict where keys and values can be either Unicode or bytes-like
        objects.
    boundary:
        If specified a Unicode object, it's used as the boundary. Otherwise
        a random boundary is generated.

View on GitHub (pinned to 956b8c5855)

Solutions

  1. Update youtube-dl; the multipart form boundary collided with the payload data.

When it happens

Trigger: Thrown at youtube_dl/utils.py:4352 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of ytdl-org/youtube-dl@956b8c5855 (2026-08-14). Data as JSON: /api/errors/d43287e93c2697e3. Report an issue: GitHub.