requests icon indicating copy to clipboard operation
requests copied to clipboard

Support for logging is abysmal, and documentation is missing

Open jackjansen opened this issue 4 years ago • 3 comments

Attempting to change logging for requests is very complicated, can only be done application-wide (I think), and the documentation is missing.

Google finds many incorrect suggestions (mainly pointing to readthedocs documentation of requests version 0.x), the only workable information I found was at this stack overflow thread: https://stackoverflow.com/questions/10588644/how-can-i-see-the-entire-http-request-thats-being-sent-by-my-python-application

As a first step it would be good if the information from this thread (insofar as it is still correct) was included in the documentation somewhere.

But it would be a lot nicer if there was easier support for logging, possibly through a toolbelt module or something. Controlling logging on a fine-grained scale is vital, especially when you are trying to debug things like SSL-related errors (which are rather unintelligible in their own right) in a large scale application.

I understand that part of the problem is with urllib3, but I guess I have to start somewhere.

And I'm willing to help, if personpower is an issue.

jackjansen avatar Jan 21 '21 22:01 jackjansen

I guess nobody would mind if information from https://docs.python-requests.org/en/master/api/#api-changes will get its own Debugging chapter.

Merging the actual code into helper method might not be accepted as that will lead to many pull requests with different formats that people want. For example, sometimes I want HAR dump (#16) to compare with browser, sometimes to compare to curl output, and sometimes colorful thing like httpie -v.

abitrolly avatar May 03 '21 07:05 abitrolly

I think it's important to support logging. There are many code like this where I use requests:

res = requets.post(url, data) 
if res.status_code >= 400:
    logger.error(res.text)
res.raise_for_status()

I think the raise_for_status should get the requests logger and log the error response.

Further more, the method should add parameter like check=True as subprocess did.

ramwin avatar Feb 18 '22 02:02 ramwin

@ramwin as the OP of this issue I think your problem is completely different: you want help from requests to make it easier to do logging for your own application.

This report is about logging what requests itself is doing internally, to debug internal issues inside requests (or, more likely, in my code using requests or in the server that requests is communicating with).

jackjansen avatar Feb 21 '22 22:02 jackjansen