Closed MiltiadisKoutsokeras closed 11 months ago
Apparently requests
has a fallback to using chardet https://github.com/psf/requests/blob/0b4d494192de489701d3a2e32acef8fb5d3f042e/src/requests/models.py#L908 Maybe you could implement this? Or maybe we should just assume utf-8 or something...
I will provide a PR when I find the time. The proper solution would be of course to also handle properly the possible response headers in requests
package also.
PR created: https://github.com/locustio/locust/pull/2484
Another PR which uses detection instead of default utf-8
: https://github.com/locustio/locust/pull/2485
Choose the one you prefer.
Fixed
Hi,
When the content-type returned in the response is application/octet-stream I am getting the following stacktrace
Traceback (most recent call last):
File "C:\Users\princemelvin\AppData\Local\Programs\Python\Python312\Lib\site-packages\locust\user\task.py", line 343, in run
self.execute_next_task()
File "C:\Users\princemelvin\AppData\Local\Programs\Python\Python312\Lib\site-packages\locust\user\task.py", line 376, in execute_next_task
self.execute_task(self._task_queue.pop(0))
File "C:\Users\princemelvin\AppData\Local\Programs\Python\Python312\Lib\site-packages\locust\user\task.py", line 497, in execute_task
task(self.user)
File "D:\Comp_Benchmark\LoadTest\download_512mb_to_file_4mb_1task_fullfile.py", line 49, in t
with self.rest("GET", url = blob_url_sas, headers = {"x-ms-range" : f"bytes={runningOffset}-{runningOffset + length}", "Accept" : "application/octet-stream"}) as response:
File "C:\Users\princemelvin\AppData\Local\Programs\Python\Python312\Lib\contextlib.py", line 137, in __enter__
return next(self.gen)
^^^^^^^^^^^^^^
File "C:\Users\princemelvin\AppData\Local\Programs\Python\Python312\Lib\site-packages\locust\contrib\fasthttp.py", line 383, in rest
if resp.text is None:
^^^^^^^^^
File "C:\Users\princemelvin\AppData\Local\Programs\Python\Python312\Lib\site-packages\locust\contrib\fasthttp.py", line 473, in text
return str(self.content, self.encoding, errors="replace")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LookupError: unknown encoding: None
Since we are checking resp.text is None it is failing the request. Should we do resp.Content check as well if resp.text is None since text encoding couldn't be detected?
Are you really on latest version?
Yes. locust 2.19.1 from C:\Users\princemelvin\AppData\Local\Programs\Python\Python312\Lib\site-packages\locust (python 3.12.0)
Ah, my line numbers weren't matching yours because there had been a few more changes to the file after the release.
I'll change it to check .content instead.
or... will that help? .content isnt None in your case, is it? PR welcome :)
Yeah it isn't none. I'll be happy to raise a PR. Will do it by today or tomorrow.
Raised a PR - https://github.com/locustio/locust/pull/2512, Please review and let me know.
Prerequisites
Description
When the tested HTTP server returns a Response header of
content-type
that is not handled by the external library method requests.utils.get_encoding_from_headers properly (for examplecontent-type: application/problem+json
) the calling code sets encoding to empty string which results in a bytes to string encoding error here. The thrown exception stack trace:Command line
locust --web-host 127.0.0.1 --web-port 9999 -f locustfile.py
Locustfile contents
Python version
3.9.2
Locust version
2.19.0
Operating system
Debian 11