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

2.18 - fasthttp error for no content response #2450

Closed
2 tasks done
scottARob opened this issue Nov 7, 2023 · 4 comments · Fixed by #2451
Closed
2 tasks done

2.18 - fasthttp error for no content response #2450

scottARob opened this issue Nov 7, 2023 · 4 comments · Fixed by #2451
Labels

Comments

@scottARob
Copy link
Contributor

Prerequisites

Description

Sending a request that generates a no content response is throwing a error when using fasthttp rest. This isn't happening under 2.17

Command line

Locust UI

Locustfile contents

File "/usr/local/lib/python3.11/contextlib.py", line 137, in __enter__
worker-1  |     return next(self.gen)
worker-1  |            ^^^^^^^^^^^^^^
worker-1  |   File "/opt/venv/lib/python3.11/site-packages/locust/contrib/fasthttp.py", line 382, in rest
worker-1  |     if resp.text is None:
worker-1  |        ^^^^^^^^^
worker-1  |   File "/opt/venv/lib/python3.11/site-packages/locust/contrib/fasthttp.py", line 467, in text
worker-1  |     return str(self.content, self.encoding, errors="replace")
worker-1  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
worker-1  | TypeError: str() argument 'encoding' must be str, not None

Python version

3.11

Locust version

2.18

Operating system

linux

@scottARob scottARob added the bug label Nov 7, 2023
@scottARob
Copy link
Contributor Author

scottARob commented Nov 8, 2023

I think its due to this change https://github.com/locustio/locust/pull/2416/files

it is possible that get_encoding_from_headers function will return None which will throw the above error. Need to return as a empty string as per 2.17

@cyberw
Copy link
Collaborator

cyberw commented Nov 8, 2023

Oh... yea sounds about right. Or maybe we should just not try to decode at all when there is no content? I dont have time to look at this right now...

@scottARob
Copy link
Contributor Author

scottARob commented Nov 8, 2023

Could just throw in a condition as a quick fix so are able to still utilise the requests lib

self.encoding = get_encoding_from_headers(self.headers)
if self.encoding is None:
     self.encoding = ""
self.encoding = get_encoding_from_headers(self.headers) or ""

@scottARob
Copy link
Contributor Author

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

Successfully merging a pull request may close this issue.

2 participants