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

Content-Type with version information is not properly parsed #2415

Closed
2 tasks done
andrew-potachits opened this issue Oct 6, 2023 · 0 comments
Closed
2 tasks done
Labels

Comments

@andrew-potachits
Copy link

Prerequisites

Description

My app API uses versioning (Microsoft.AspNetCore.Mvc.Versioning) with version info in the media type Content-Type header).
Thus, the responses are like this:

Content-Type: application/json; charset=utf-8; api-version=3.0

however, the FastResponse.text doesn't expect that Content-Type can have anything else after the charset=utf-8; and uses the rest of the value as content encoding.

self.encoding = self.headers.get("content-type", "").partition("charset=")[2] or "utf-8"

Getting this error:

LookupError: unknown encoding: utf-8; api-version=3.0

[2023-10-06 19:37:47,444] Andrews-Mac-Studio.local/ERROR/locust.user.task: unknown encoding: utf-8; api-version=3.0
Traceback (most recent call last):
  File "/opt/homebrew/lib/python3.11/site-packages/locust/user/task.py", line 347, in run
    self.execute_next_task()
  File "/opt/homebrew/lib/python3.11/site-packages/locust/user/task.py", line 378, in execute_next_task
    self.execute_task(self._task_queue.pop(0))
  File "/opt/homebrew/lib/python3.11/site-packages/locust/user/task.py", line 499, in execute_task
    task(self.user)
  File "/Users/andrew/Dev/temp.py", line 10, in index
    with self.rest("POST",
  File "/opt/homebrew/Cellar/python@3.11/3.11.5/Frameworks/Python.framework/Versions/3.11/lib/python3.11/contextlib.py", line 137, in __enter__
    return next(self.gen)
           ^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/locust/contrib/fasthttp.py", line 379, in rest
    if resp.text is None:
       ^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/locust/contrib/fasthttp.py", line 465, in text

Command line

locust -f temp.py --headless --host http://localhost:8888 -u 1 -r 1

Locustfile contents

from locust import FastHttpUser, between, task

class WebsiteUser(FastHttpUser):
    @task
    def index(self):
        with self.rest("POST", 
                       "/versioned-api") as res:
            pass
        self.stop()

Python version

Python 3.11.5

Locust version

locust 2.17.0 from /opt/homebrew/lib/python3.11/site-packages/locust (python 3.11.5)

Operating system

Mac OS 14.0 (23A344)

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

No branches or pull requests

1 participant