I have the following code for connecting to an existing Couchbase bucket and retrieving a document. How can I enforce a custom timeout value (in seconds) for the couchbase connections?
import couchbase
from couchbase.bucket import Bucket
import couchbase.exceptions
cb_nodes="123.456.7.89"
cb_bucket = "default"
def fetch_doc(self, key):
try:
cb = Bucket('couchbase://' + cb_nodes + '/' + cb_bucket)
doc = cb.get(key)
return doc
except couchbase.exceptions.NotFoundError as e:
print("Key Not Found")
except couchbase.exceptions.TimeoutError as e:
print("Couchbase connection timed out")
except couchbase.exceptions.CouchbaseNetworkError as e:
print("Couchbase Connection failed")
I am using Python 3, Couchbase 4.1 and Python SDK 2.1 for Couchbase.
I found this - https://developer.couchbase.com/documentation/server/4.1/developer-guide/error-handling.html#concept_ybj_tqs_zs__devguide-transient-errors but it does not really state how or where I should set a timeout value.
Another question - How can I make the python client to retry fetching a document when it encounters a timeout and network exception?
Any help with this is greatly appreciated.
Thanks!