How to use the messagebird.client.ErrorException function in messagebird

To help you get started, we’ve selected a few messagebird examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github messagebird / python-rest-api / examples / balance.py View on Github external
ACCESS_KEY = 'test_gshuPaZoeEG6ovbc8M79w0QyM'

try:
  # Create a MessageBird client with the specified ACCESS_KEY.
  client = messagebird.Client(ACCESS_KEY)

  # Fetch the Balance object.
  balance = client.balance()

  # Print the object information.
  print('\nThe following information was returned as a Balance object:\n')
  print('  amount  : %d' % balance.amount)
  print('  type    : %s' % balance.type)
  print('  payment : %s\n' % balance.payment)

except messagebird.client.ErrorException as e:
  print('\nAn error occured while requesting a Balance object:\n')

  for error in e.errors:
    print('  code        : %d' % error.code)
    print('  description : %s' % error.description)
    print('  parameter   : %s\n' % error.parameter)
github messagebird / python-rest-api / examples / number_available_list.py View on Github external
print('  Containing the the following items:')
        for item in numbers.items:
            print('  {')
            print('    number                : %s' % item.number)
            print('    country               : %s' % item.country)
            print('    region                : %s' % item.region)
            print('    locality              : %s' % item.locality)
            print('    features              : %s' % item.features)
            print('    tags                  : %s' % item.tags)
            print('    type                  : %s' % item.type)
            print('    status                : %s' % item.status)
            print('  },')
    else:
        print('  With an empty response.')

except messagebird.client.ErrorException as e:
    print('\nAn error occured while requesting a NumberList object:\n')

    for error in e.errors:
        print('  code        : %d' % error.code)
        print('  description : %s' % error.description)
        print('  parameter   : %s\n' % error.parameter)

except requests.exceptions.HTTPError as e:
    print('\nAn HTTP exception occurred while fetching all purchased phone numbers:')
    print(' ', e)
    print('  Http request body: ', e.request.body)
    print('  Http response status: ', e.response.status_code)
    print('  Http response body: ', e.response.content.decode())

except Exception as e:
    print('\nAn ', e.__class__, ' exception occurred while :')
github messagebird / python-rest-api / examples / conversation_create_message.py View on Github external
parser.add_argument('--channelId', help='channel ID that you want to create a message for', type=str, required=True)
parser.add_argument('--message', help='message that you want to send', type=str, required=True)
args = vars(parser.parse_args())

try:
    client = messagebird.Client(args['accessKey'])

    msg = client.conversation_create_message(args['conversationId'],
                                             {'channelId': args['channelId'], 'type': MESSAGE_TYPE_TEXT,
                                              'content': {'text': args['message']}})

    # Print the object information.
    print('The following information was returned as a Conversation List object:')
    print(msg)

except messagebird.client.ErrorException as e:
    print('An error occured while requesting a Message object:')

    for error in e.errors:
        print('  code        : %d' % error.code)
        print('  description : %s' % error.description)
        print('  parameter   : %s\n' % error.parameter)
github messagebird / python-rest-api / examples / conversation_list_webhook.py View on Github external
import messagebird

parser = argparse.ArgumentParser()
parser.add_argument('--accessKey', help='access key for MessageBird API', type=str, required=True)
args = vars(parser.parse_args())

try:
    client = messagebird.Client(args['accessKey'])

    webhook_list = client.conversation_list_webhooks()

    # Print the object information.
    print('The following information was returned as a Conversation Webhook List object:')
    print(webhook_list)

except messagebird.client.ErrorException as e:
    print('An error occured while requesting a Conversation Webhook List object:')

    for error in e.errors:
        print('  code        : %d' % error.code)
        print('  description : %s' % error.description)
        print('  parameter   : %s\n' % error.parameter)
github messagebird / python-rest-api / examples / number_purchase.py View on Github external
# Purchase number
    number = client.purchase_number('3197010240126', 'NL', 3)

    # Print the object information.
    print('\nThe following information was returned as a Number object:\n')
    print('    number                : %s' % number.number)
    print('    country               : %s' % number.country)
    print('    region                : %s' % number.region)
    print('    locality              : %s' % number.locality)
    print('    features              : %s' % number.features)
    print('    tags                  : %s' % number.tags)
    print('    type                  : %s' % number.type)
    print('    status                : %s' % number.status)

except messagebird.client.ErrorException as e:
    print('\nAn error occured while requesting a NumberList object:\n')

    for error in e.errors:
        print('  code        : %d' % error.code)
        print('  description : %s' % error.description)
        print('  parameter   : %s\n' % error.parameter)

except requests.exceptions.HTTPError as e:
    print('\nAn HTTP exception occurred while fetching all purchased phone numbers:')
    print(' ', e)
    print('  Http request body: ', e.request.body)
    print('  Http response status: ', e.response.status_code)
    print('  Http response body: ', e.response.content.decode())

except Exception as e:
    print('\nAn ', e.__class__, ' exception occurred while :')
github messagebird / python-rest-api / examples / lookup_hlr.py View on Github external
# Create a new Lookup HLR object.
  lookup_hlr = client.lookup_hlr(PHONE_NUMBER)

  # Print the object information.
  print('\nThe following information was returned as a Lookup HLR object:\n')
  print('  id              : %s' % lookup_hlr.id)
  print('  href            : %s' % lookup_hlr.href)
  print('  msisdn          : %d' % lookup_hlr.msisdn)
  print('  network         : %d' % lookup_hlr.network)
  print('  reference       : %s' % lookup_hlr.reference)
  print('  status          : %s' % lookup_hlr.status)
  print('  details         : %s' % lookup_hlr.details)
  print('  createdDatetime : %s' % lookup_hlr.createdDatetime)
  print('  statusDatetime  : %s\n' % lookup_hlr.statusDatetime)

except messagebird.client.ErrorException as e:
  print('\nAn error occured while requesting a Lookup HLR object:\n')

  for error in e.errors:
    print('  code        : %d' % error.code)
    print('  description : %s' % error.description)
    print('  parameter   : %s\n' % error.parameter)