【问题标题】:Couchbase Python SDK - How to enforce a custom couchbase connection timeout?Couchbase Python SDK - 如何强制执行自定义的 couchbase 连接超时?
【发布时间】:2017-05-08 12:23:14
【问题描述】:

我有以下代码用于连接到现有的 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 使用 Python 3、Couchbase 4.1 和 Python SDK 2.1。

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

非常感谢任何帮助。

谢谢!

【问题讨论】:

    标签: python couchbase connection-timeout


    【解决方案1】:

    current Client Settings section of the Couchbase Documentation 涵盖了包括超时在内的各种设置。你指的链接有点老了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-01-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多