-
Notifications
You must be signed in to change notification settings - Fork 39
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
httpx.RequestNotRead: Attempted to access request content, without having called read()
#83
Comments
Thanks for finding and raising this issue! You should be able to solve it non-hacky in your test by calling That being said, I don't think it should be needed, since both currently open PR #82 and closed #68 deals with pre-reading stream/content of the It's quite easy to add a request pre-read to #82 that should solve your issue. Will try to add this before merging it. FYI, the RESPX pass-through feature is what makes this "hard", since if we always pre-read request and response for a pattern marked as |
An alternative solution would be to enhance the request "method" call with a matching functionality on content ("content matcher" parameter - similar to what |
Do you mean that if we extend Sounds like a great feature anyhow, will add a separate issue for that. I think we should support both. |
Yes, I meant matching the You have just to be careful, to not overwhelm users of |
FYI @max-iov42, #106 adds support for content pattern matching, etc. 😉 |
I would like to test if a client uses the REST interface in a proper way. I wanted to use
respx
to mock the HTTP requests. I found no easy way to test the content of the HTTP request sent to the service.What I would expect:
content
attribute on theRequest
object returned by thecalls
to verify correctness of the request.What happens:
content
attribute throws anhttpx.RequestNotRead
exceptionstream._body
attribute which is kind of a hack. Or maybe I don not use the library in a proper way and the documentation should show this kind of example.Used Environment:
Here the minimal example code:
Calling this with pytest:
The text was updated successfully, but these errors were encountered: