Search code examples
pythonbox-api

Filtering out warnings from Box SDK (Python)


The Box API is noisy ... very helpful for diagnosing, and yet for production code I'd like less noise.

I tried this:

warnings.filterwarnings(
    action='ignore',
    # category=Warning,
    # module=r'boxsdk.*'
)

but I still see this:

WARNING:boxsdk.network.default_network:"POST
https://api.box.com/oauth2/token" 400 83
{'Date': 'Sat, 28 Nov 2020 04:30:03 GMT', 'Content-Type':
'application/json', 'Transfer-Encoding': 'chunked', 'Connection':
'keep-alive', 'Str....

My code as written I think should filter ALL warnings.


Solution

  • You can set logging level of boxsdk module to ERROR or CRITICAL. It will allow you to disable logging of warning messages generated by boxsdk:

    import logging
    logging.getLogger('boxsdk').setLevel(logging.CRITICAL)