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

locust.contrib.fasthttp.FastHttpLocust does not support multipart/form-data #1252

Closed
pcdinh opened this issue Feb 4, 2020 · 2 comments
Closed

Comments

@pcdinh
Copy link

pcdinh commented Feb 4, 2020

Describe the bug

I tried to upload a file using FastHttpLocust and got an exception

  File "c:\python37\lib\site-packages\locust\contrib\fasthttp.py", line 236, in post
    return self.request("POST", path, data=data, **kwargs)
  File "c:\python37\lib\site-packages\locust\contrib\fasthttp.py", line 178, in request
    response = self._send_request_safe_mode(method, url, payload=data, headers=headers, **kwargs)
  File "c:\python37\lib\site-packages\locust\contrib\fasthttp.py", line 124, in _send_request_safe_mode
    return self.client.urlopen(url, method=method, **kwargs)
  File "c:\python37\lib\site-packages\geventhttpclient\useragent.py", line 333, in urlopen
    req = self._make_request(url, method=method, headers=headers, payload=payload)
  File "c:\python37\lib\site-packages\geventhttpclient\useragent.py", line 285, in _make_request
    raise NotImplementedError
NotImplementedError

The geventhttpclient code confirms that this feature is not supported

    def _make_request(self, url, method='GET', headers=None, payload=None):
        req_headers = self.default_headers.copy()
        if headers:
            req_headers.update(headers)
        if payload:
            # Adjust headers depending on payload content
            content_type = req_headers.get('content-type', None)
            if not content_type and isinstance(payload, dict):
                req_headers['content-type'] = "application/x-www-form-urlencoded; charset=utf-8"
                payload = urlencode(payload)
            elif not content_type and isinstance(payload, text_type):
                req_headers['content-type'] = 'text/plain; charset=utf-8'
            elif not content_type:
                req_headers['content-type'] = 'application/octet-stream'
            elif content_type.startswith("multipart/form-data"):
                # See restkit for some example implementation
                # TODO: Implement it
                raise NotImplementedError
        return CompatRequest(url, method=method, headers=req_headers, payload=payload)

I expect that feature is supported. If it is not available for the moment, the document should mention it.

  • OS: Windows 10, Ubuntu 18
  • Python version: 3.7
  • Locust version: 0.13.5, 0.14.4
  • Locust command line that you ran: locust --no-web -c 15 -r 1 --only-summary --host=http://localhost:5000 -f client/upload_loadtests.py
  • Locust file contents (anonymized if necessary):
@pcdinh pcdinh added the bug label Feb 4, 2020
@cyberw
Copy link
Collaborator

cyberw commented Feb 5, 2020

Hi! Unfortunately this is in the geventhttpclient code base so it is hard for us to fix. I would suggest falling back to HttpLocust for now.

@cyberw cyberw added the hacktoberfest See https://hacktoberfest.digitalocean.com for more info label Sep 28, 2020
@cyberw cyberw removed the hacktoberfest See https://hacktoberfest.digitalocean.com for more info label Oct 31, 2020
@cyberw cyberw added the invalid label Mar 15, 2021
@cyberw cyberw closed this as completed Mar 15, 2021
@MiltiadisKoutsokeras
Copy link
Contributor

What about this PR: geventhttpclient/geventhttpclient#159

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

No branches or pull requests

3 participants