Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sending multipart/form-data #521

Closed
kmiller9292 opened this issue Jan 19, 2017 · 6 comments
Closed

Sending multipart/form-data #521

kmiller9292 opened this issue Jan 19, 2017 · 6 comments

Comments

@kmiller9292
Copy link

kmiller9292 commented Jan 19, 2017

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
@bruceadams
Copy link

post takes many named arguments. Please give names for the named arguments, like this:

i.client.post("/tji8setj", files=files, headers=headers)

@kmiller9292
Copy link
Author

@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.

@bruceadams
Copy link

Hmm, can you let Requests set the Content-Type header? It just worked for me, without my setting Content-Type.

@kmiller9292
Copy link
Author

@bruceadams I have done as you suggested (edited original post again) which did correct the content type issue, but it still seems like the files are corrupted. I'm not sure if this is a product of the fact that the files are Jpeg images or that I am on Windows (or both) which is odd since everything appears to be correct now.

@justiniso
Copy link
Member

Glad to hear there was at least resolution to the original issue! The corrupted files are not a locust issue as far as I can tell. Seems more like an issue between requests and your server. Discussion is welcome to continue but I'm going to close this issue to keep focus on locust-specific problems.

For future debugging, it would be helpful to clarify what you mean by "corrupted." Headers missing? Empty content? Second half missing? One character off?

@nitesh31mishra
Copy link

@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....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants