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
logging of raw request/response #6884
Comments
Why didn't you just use Wireshark? When debugging network issues, people tend to end up using it anyway. I don't think that every web framework is supposed to reimplement the wheel. |
Maybe our docs should link to Wireshark? 💭 |
Because it's https traffic and I don’t have twilio’s private key to be able to decode the traffic using wireshark.
I also sometimes find it useful to log all http conversations in an application so that I can troubleshoot problems after the fact. This is particularly useful for problems that are difficult to reproduce.
With regards to other frameworks, I was able to implement a wrapper around the requests library that allowed me to log traffic without much difficulty, but the structure of your code required a lot more monkey-patching.
|
You should be able to use |
This is helpful to know about wireshark, though it doesn't solve my entire use-case. The first link you sent shows a really useful hook in SSLContext that would give me what I'm looking for. However, I would still have a use-case for logging unencrypted traffic, too. For example, in several of my applications I log successful http client requests/responses at a DEBUG level and failed responses ( any http 4XX for example ) at a WARNING level. This way my users can choose to log all traffic or only traffic that has a problem. Again, logging this traffic is a boon when troubleshooting applications that aren't working correctly without having to try to reproduce the problem with wireshark running. |
Is your feature request related to a problem?
I have scenarios where I need to be able to see the raw request/response for a given HTTP interaction. For example, I'm currently getting a 401 unauthorized back from Twilio, and I need to see the raw request/response to diagnose why it's failing because I know the credentials are correct (I know this because I had to convert some lua code to python and the code and credentials were working without a problem in lua).
This is also useful when trying to prove to an API vendor that they're doing something wrong like sending an html content-type but the content itself is obviously json, etc.
Describe the solution you'd like
I'd like a simple, clean, supported way to opt-in to raw logging of requests/responses. This would probably be cleanest by allowing an optional logging callback in ClientSession's init() as well as the individual request methods, for example:
or if I didn't want session-wide logging:
Alternatively, you could do something like this:
This would require users to explicitly enable a logging level of 1 ( which is less even than logging.DEBUG ) in order to opt-in to this behavior.
Describe alternatives you've considered
I created the following abomination to meet my current needs, but it is likely to break everytime the developers sneeze:
Related component
Client
Additional context
sample output from a test performed against a little netgear switch on my network:
Code of Conduct
The text was updated successfully, but these errors were encountered: