The LoggingNetwork network layer is a great tool for debugging your Python SDK applications, or just quickly making requests to the Box Content API.
In [1]:
from boxsdk import Client, OAuth2
from boxsdk.network.logging_network import LoggingNetwork
In [2]:
import logging
root_logger = logging.getLogger()
for handler in root_logger.handlers:
root_logger.removeHandler(handler)
In [3]:
# Create a new instance of the logging network to be used for auth and API requests
logging_network = LoggingNetwork()
# Create an auth object that uses a developer token
DEV_TOKEN = 'g3T46nWfprIRhuHyjfD5LBldwkFEG1RP'
auth = OAuth2(client_id=None, client_secret=None, access_token=DEV_TOKEN)
# Create an API client that uses the logging network layer
client = Client(auth, network_layer=logging_network)
In [4]:
# Make an API call to get the current user
me = client.user('me').get()
In [6]:
from boxsdk.exception import BoxAPIException
# Make an API call to get a nonexistent file
try:
four_oh_four = client.file('404').get()
except BoxAPIException:
pass
Requests are logged in blue; successful responses in green, error responses in red.