question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Sending multipart/form-data

See original GitHub issue

I’m attempting to send a rather simple test to a server that requires post requests to be sent as multipart/form-data, however I am receiving an error when attempting to send the request. Error below:

TypeError: post() takes at most 4 arguments (5 given)

The code written is rather simple and I believe it follows all of locust’s requirements, however I am not sure why the error is occurring as my post only has 4 arguments. Code below:

from locust import HttpLocust, TaskSet, task

files = [
        ('front', ('image_front.jpg', open('image_front.jpg', 'rb'), 'image/jpeg')),
        ('back', ('image_back.jpg', open('image_back.jpg', 'rb'), 'image/jpeg'))]

class MyTaskSet(TaskSet):
    @task
    def image(i):
        i.client.post("/tji8setj", files=files)

class MyLocust(HttpLocust):
    task_set = MyTaskSet
    min_wait = 5000
    max_wait = 15000

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
kmiller9292commented, Feb 3, 2017

@bruceadams That seems to have done the trick as far as sending as multi-part is concerned, thanks! However I did notice that the files seem to get corrupted at some point during the request but I’m not sure if that’s a product of how the request is being sent, or if it has something to do with setting an improper boundary. I edited my original post with the boundary I set, but am not sure if it is correct.

0reactions
nitesh31mishracommented, May 25, 2021

@bruceadams That seems to have done the trick as far as sending as multi-part is concerned, thanks! However I did notice that the files seem to get corrupted at some point during the request but I’m not sure if that’s a product of how the request is being sent, or if it has something to do with setting an improper boundary. I edited my original post with the boundary I set, but am not sure if it is correct.

I am also facing same issue my image file is getting corrupted…

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to send multipart/form-data request using Postman [closed]
UPDATE: I have created a video on sending multipart/form-data requests to explain this better. Actually, Postman can do this. enter image description here....
Read more >
How to Multipart File Upload Using FormData with HTML | refine
A multipart request is a HTTP request that HTTP clients construct to send files and data over to a HTTP Server. It is...
Read more >
Upload Data using Multipart. <form action ... - Medium
The enctype attribute specifies how the form-data should be encoded when submitting it to the server. Multipart/form-data is one of the most used ......
Read more >
Using FormData Objects - Web APIs | MDN
The FormData object lets you compile a set of key/value pairs to send using XMLHttpRequest. It is primarily intended for use in sending...
Read more >
Uploading File From a Web Page Using Multipart Form POST
Specify enctype="multipart/form-data" attribute on a form tag. · Add a name attribute to a single input type="file" tag. · DO NOT add a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found