Skip to main content
Question

BoxApiException - Suppress warnings

  • May 22, 2025
  • 2 replies
  • 51 views

Forum|alt.badge.img

I am trying to capture exceptions. I can capture error code 404 and 409 fine, but not 429(Request rate limit exceeded). The other issue with 404/409/429 is that I get this warnings show up on the screen (in red font). I am wondering on how to suppress these messages. Here is an example.

"POST https://upload.box.com/api/2.0/files/content" 409 464
{'Date': 'Sun, 07 Apr 2019 05:01:27 GMT', 'Content-Type': 'application/json', 'Content-Length': '464', 'Connection': 'keep-alive', 'Cache-Control': 'no-cache, no-store', 'Vary': 'Accept-Encoding', 'Strict-Transport-Security': 'max-age=31536000', 'Age': '2'}
{'code': '---_use',
 'context_info': {'conflicts': {'etag': '0',
                                'file_version': {'id': '460300807095',
                                                 'sha1': '3a1a03c6e4d5d2f478dd53488149c70f908ab6ae',
                                                 'type': 'file_version'},
                                'id': '43***phone number removed for privacy***',
                                'name': '921.bin',
                                'sequence_id': '0',
                                'sha1': '3a1a03c6e4d5d2f478dd53488149c70f908ab6ae',
                                'type': 'file'}},
 'help_url': 'http://developers.box.com/docs/#errors',
 'message': 'Item with the same name already exists',
 'request_id': 'dtrff7g1tzgtydf4',
 'status': 409,
 'type': 'error'}

Here is my code.

        try:
            box_response = client.as_user(next(get_next)).folder(folder_id=target_folder).upload("/root/files/"+filename, file_name=filename)
        except BoxAPIException as box_api_exception:
            status       = box_api_exception.status
            code         = box_api_exception.code
            message      = box_api_exception.message
            context_info = box_api_exception.context_info
            print(context_info['errors'][0]['message'])
            if status == 404:
                print("%s,%s,%s" % (status,message,filename))
            elif status == 409:
                print("%s,%s,%s" % (status,message,filename))
            elif status == 429:
                print("%s,%s,%s" % (status,message,filename))
                time.sleep(10)

 

TIA

 

Shynee

2 replies

Forum|alt.badge.img

Had to open a case with BOX support. Here is the solution which worked perfectly.

 

from logging.handlers import SysLogHandler, logging

logging.basicConfig(level=logging.CRITICAL)

 

 


Forum|alt.badge.img

Thanks  for posting your answer back to the forums – hopefully this can help other community members with a similar problem!

 

Thanks for making the Box Community better!

 

-Scott