Couchbase PythonSDK如何强制自定义Couchbase连接超时?

2024-04-25 14:22:10 发布

您现在位置:Python中文网/ 问答频道 /正文

我有以下代码来连接到现有的Couchbase bucket并检索文档。如何为couchbase连接强制自定义超时值(以秒为单位)?在

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")

我正在为Couchbase使用python3、Couchbase 4.1和pythonsdk2.1。在

我找到了这个-https://developer.couchbase.com/documentation/server/4.1/developer-guide/error-handling.html#concept_ybj_tqs_zs__devguide-transient-errors,但它并没有真正说明我应该如何或在哪里设置超时值。在

如有任何帮助,我们将不胜感激。在

谢谢!在


Tags: keyimportdeveloperdocbucketasexceptionsnodes