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.
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)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
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"