Is there a way to clear the logs from the Requests library?

Asked 2 years ago, Updated 2 years ago, 81 views

In default settings, the Requests library continues to write log messages to the console (such as Starting new HTTP connection...), which is so annoying.

How can I set it so that it doesn't look like that?

python logging python-request

2022-09-22 12:01

1 Answers

You must set the logging level of the request separately using the logging module.

I think it's right to send an error or warning separately, so I set it to log at least in warning.

import logging

logging.getLogger("requests").setLevel(logging.WARNING)

If you want to apply the same to urlib3 library, please add this too

logging.getLogger("urllib3").setLevel(logging.WARNING)


2022-09-22 12:01

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.