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

'NoneType' object has no attribute 'get' when stream=True in FastHttpSession.request #2640

Closed
2 tasks done
neiser opened this issue Mar 18, 2024 · 2 comments · Fixed by #2642
Closed
2 tasks done

'NoneType' object has no attribute 'get' when stream=True in FastHttpSession.request #2640

neiser opened this issue Mar 18, 2024 · 2 comments · Fixed by #2642
Labels

Comments

@neiser
Copy link
Contributor

neiser commented Mar 18, 2024

Prerequisites

Description

I'm using the request(..., stream=True) in my task and occasionally, I get the following stack trace (slightly redacted):

'NoneType' object has no attribute 'get'
...
  File ".../locustfile.py", line XXX, in some_task
    with self.client.post("/some-path",
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../lib/python3.11/site-packages/locust/contrib/fasthttp.py", line 284, in post
    return self.request("POST", url, data=data, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../lib/python3.11/site-packages/locust/contrib/fasthttp.py", line 236, in request
    request_meta["response_length"] = int(response.headers.get("response_length") or 0)

The issue happens when there's a network connectivity problem, making response having no response.headers object.

Maybe a somewhat safer approach around the code

if stream:
    request_meta["response_length"] = int(response.headers.get("response_length") or 0)

in FastHttpSession.request is necessary?

Command line

Executed via IDE Debugger (does not matter)

Locustfile contents

class SimpleUser(FastHttpUser):
    @task(1)
    def some_task(self):
        with self.client.post("/some-path", stream=True) as resp:
            pass

Python version

3.11

Locust version

2.24.0

Operating system

Linux

@cyberw
Copy link
Collaborator

cyberw commented Mar 18, 2024

Thanks for reporting! install the latest build using pip install --pre locust (available in a few minutes) and try it out!

@neiser
Copy link
Contributor Author

neiser commented Mar 18, 2024

See also #2643, which makes streaming and error handling eventually work for me at the same time.

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