Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I disable log messages from the Requests library?

By default, the Requests python library writes log messages to the console, along the lines of:

Starting new HTTP connection (1): example.com http://example.com:80 "GET / HTTP/1.1" 200 606 

I'm usually not interested in these messages, and would like to disable them. What would be the best way to silence those messages or decrease Requests' verbosity?

like image 275
aknuds1 Avatar asked Jun 14 '12 08:06

aknuds1


People also ask

What are logging messages?

The message logging facility, when active, writes messages to the log data set containing all data that simulated resources transmit or receive in a specified network.


1 Answers

I found out how to configure requests's logging level, it's done via the standard logging module. I decided to configure it to not log messages unless they are at least warnings:

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

If you wish to apply this setting for the urllib3 library (typically used by requests) too, add the following:

logging.getLogger("urllib3").setLevel(logging.WARNING) 
like image 188
aknuds1 Avatar answered Sep 16 '22 13:09

aknuds1