Skip to content
Visit booth 3171 at Google Cloud Next to see how to unlock real-time decisions at scaleMore info

Error handling

On error, the Aerospike Python client raises an AerospikeError exception or one of its subclasses. The exception includes the following attributes:

  • code — The error code that identifies the error. See as_status.h of the Aerospike C client for error code descriptions.
  • msg — The error message with details.
  • file — The file where the error occurred.
  • line — The line number in the file where the error occurred.

Exception Handling

To handle the exceptions, wrap the code in a try-except block:

from __future__ import print_function
import aerospike
from aerospike.exception import *
try:
config = { 'hosts': [ ('127.0.0.1', 3000)], 'policies': { 'timeout': 1200}}
client = aerospike.client(config).connect()
client.close()
except ClientError as e:
print("Error: {0} [{1}]".format(e.msg, e.code))
Feedback

Was this page helpful?

What type of feedback are you giving?

What would you like us to know?

+Capture screenshot

Can we reach out to you?