Skip to content

Help unit testing v3 multipart/form-data with "Missing boundary in multipart" #1964

Closed Answered by RobbeSneyders
alanbchristie asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @alanbchristie,

The boundary parameter is required in the Content-Type header for multipart/form-data

Eg.

headers={"Content-Type": b"multipart/form-data; boundary=-"}

Usually multipart/form-data is only used when your form includes files, otherwise it is indeed recommended to use application/x-www-form-urlencoded.

If really needed, you can force the test client to send data as multipart/form-data as follows:

res = app_client.post(
    "/v1.0/multipart_form_json",
    files={"file": b""},  # Force multipart/form-data content-type
    data={"x": json.dumps({"name": "joe", "age": 20})},
)

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by RobbeSneyders
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants