pythoncouchbase

Cannot connect to my couchbase cluster with python SDK


I can reach my couchbase cluster with a simple cURL:

curl -u $CB_USERNAME:$CB_PASSWORD  http://$CB_HOST/pools/default/buckets

but I do not manage to connect using the Python SDK:

from datetime import timedelta
from couchbase.auth import PasswordAuthenticator
from couchbase.cluster import Cluster
from couchbase.options import ClusterOptions
import os

# Configuration
CB_HOST = os.environ.get('CB_HOST')
CB_BUCKET = os.environ.get('CB_BUCKET')
CB_USERNAME = os.environ.get('CB_USERNAME')
CB_PASSWORD = os.environ.get('CB_PASSWORD')

# Initialize Couchbase connection
auth = PasswordAuthenticator(CB_USERNAME, CB_PASSWORD)
options = ClusterOptions(auth)
cluster = Cluster(f'couchbase://{CB_HOST}', options)

This gives this error:

Traceback (most recent call last):
  File "/Users/luc/code/couchbase/examples/main.py", line 27, in <module>
    cluster = Cluster(f'couchbase://{CB_HOST}', options)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/luc/code/couchbase/examples/venv/lib/python3.11/site-packages/couchbase/cluster.py", line 99, in __init__
    self._connect()
  File "/Users/luc/code/couchbase/examples/venv/lib/python3.11/site-packages/couchbase/logic/wrappers.py", line 98, in wrapped_fn
    raise e
  File "/Users/luc/code/couchbase/examples/venv/lib/python3.11/site-packages/couchbase/logic/wrappers.py", line 82, in wrapped_fn
    ret = fn(self, *args, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/luc/code/couchbase/examples/venv/lib/python3.11/site-packages/couchbase/cluster.py", line 105, in _connect
    raise ErrorMapper.build_exception(ret)
couchbase.exceptions.UnAmbiguousTimeoutException: UnAmbiguousTimeoutException(<ec=14, category=couchbase.common, message=unambiguous_timeout (14), C Source=/Users/couchbase/jenkins/workspace/python/sdk/python-packaging-pipeline/py-client/src/connection.cxx:199>)

Any hints what I'm doing wrong ?


Solution

  • Just to eliminate possible network/connectivity issues, I suggest running SDK Doctor.

    From the docs:

    SDK doctor is a tool to diagnose application-server-side connectivity issues with your Couchbase Cluster. It makes the same connections to the Couchbase Server cluster that Couchbase SDKs make during bootstrapping, and then reports on the state of the connections made — giving diagnostic information that can help to solve puzzling network issues.

    Hopefully that will help you identify any issues.