Runtime ErrorAll platformspython-multipart 0.0.6+

TypeError: can't concat _io.BytesIO to bytes

pip install python-multipart
from multipart import MultipartParser
from io import BytesIO
parser = MultipartParser(BytesIO(body), content_type)
TypeError: can't concat _io.BytesIO to bytes
File ".../multipart/multipart.py", line 84
boundary = b"\r\n--" + boundary

python-multipart 0.0.6 changed how boundary bytes are handled internally. Code written against the old API passes a BytesIO stream where bytes are expected during boundary concatenation (b"\r\n--" + boundary), causing TypeError. This surfaces most often in hand-rolled FastAPI or Starlette multipart parsers that construct MultipartParser directly.

Any · python-multipart 0.0.6+
old API · failsparse_form_data · ok
Any · python-multipart 0.0.5
old API · ok (unsupported)

1Use parse_form_data instead of MultipartParser directlyEasiest

The high-level parse_form_data function handles boundary extraction and stream management for you. It works across all python-multipart versions and is the recommended API.

from multipart import parse_form_data
from io import BytesIO

# works with raw bytes body
environ = {
    "REQUEST_METHOD": "POST",
    "CONTENT_TYPE": content_type,
    "CONTENT_LENGTH": str(len(body)),
    "wsgi.input": BytesIO(body),
}
forms, files = parse_form_data(environ)
2Pass bytes, not BytesIO, and extract boundary separatelyMedium

If you must use MultipartParser directly, extract the boundary from the Content-Type header as a plain string and ensure stream is a true bytes-like object.

from multipart import MultipartParser
import cgi

_, params = cgi.parse_header(content_type)
boundary = params["boundary"].encode()  # str → bytes
parser = MultipartParser(body, boundary)  # body = raw bytes
3Pin python-multipart to 0.0.5Alternative

Temporary workaround only — 0.0.5 is unmaintained and has known security issues. Migrate to the new API as soon as possible.

pip install "python-multipart==0.0.5"

python-multipart · Compatibility Matrix
See install results across all Python versions and operating systems
Observed in 430 searches · Last verified Aug 2026
TypeError: can't concat _io.BytesIO to bytes — python-multipart