UnambiguousTimeoutException while trying to connect with Python SDK

I’ve been trying to connect to Couchbase Capella using the example shown in the Connect option in the cluster. I’m using Python 3.9, Docker, Django 4.0, and Couchbase 4.0.5 in a macOS. And the following error is being visible. Moreover, I’ve kept my allowed IPs to 0.0.0.0.

gdmp-core  | Traceback (most recent call last):
gdmp-core  |   File "/usr/local/lib/python3.10/dist-packages/django/core/handlers/exception.py", line 55, in inner
gdmp-core  |     response = get_response(request)
gdmp-core  |   File "/usr/local/lib/python3.10/dist-packages/django/core/handlers/base.py", line 197, in _get_response
gdmp-core  |     response = wrapped_callback(request, *callback_args, **callback_kwargs)
gdmp-core  |   File "/usr/local/lib/python3.10/dist-packages/django/views/generic/base.py", line 103, in view
gdmp-core  |     return self.dispatch(request, *args, **kwargs)
gdmp-core  |   File "/usr/local/lib/python3.10/dist-packages/django/views/generic/base.py", line 142, in dispatch
gdmp-core  |     return handler(request, *args, **kwargs)
gdmp-core  |   File "/app/user/views.py", line 9, in get
gdmp-core  |     return JsonResponse(user.connect(), safe=False)
gdmp-core  |   File "/app/core/database/couchbase.py", line 39, in connect
gdmp-core  |     cluster = Cluster('couchbases://{}'.format(host), ClusterOptions(authenticator=auth, enable_tls=True))
gdmp-core  |   File "/usr/local/lib/python3.10/dist-packages/couchbase/cluster.py", line 99, in __init__
gdmp-core  |     self._connect()
gdmp-core  |   File "/usr/local/lib/python3.10/dist-packages/couchbase/logic/wrappers.py", line 101, in wrapped_fn
gdmp-core  |     raise e
gdmp-core  |   File "/usr/local/lib/python3.10/dist-packages/couchbase/logic/wrappers.py", line 85, in wrapped_fn
gdmp-core  |     ret = fn(self, *args, **kwargs)
gdmp-core  |   File "/usr/local/lib/python3.10/dist-packages/couchbase/cluster.py", line 105, in _connect
gdmp-core  |     raise ErrorMapper.build_exception(ret)
gdmp-core  | couchbase.exceptions.UnAmbiguousTimeoutException: <ec=14, category=couchbase.common, message=unambiguous_timeout (14), C Source=/home/ec2-user/workspace/python/sdk/python-manylinux-wheel-pipeline/couchbase-python-client/src/connection.cxx:199>

Hi @ab.mon421 - I would suggest you try increasing some of the timeouts. It is possible that default timeouts can be too short when using a development environment across the internet. I should note that in production the expectation is deployment in the same region. I have provided some snippets below. I hope this helps.

Basic use of ClusterTimeoutOptions.

from datetime import timedelta

# needed for any cluster connection
from couchbase.auth import PasswordAuthenticator
from couchbase.cluster import Cluster

# needed for options -- cluster, timeout, SQL++ (N1QL) query, etc.
from couchbase.options import (ClusterOptions,
                               ClusterTimeoutOptions,
                               QueryOptions)

# Update this to your cluster
endpoint = '--your-instance--.dp.cloud.couchbase.com'
username = 'username'
password = 'password'
bucket_name = 'bucketname'
# not needed w/ 4.x SDK
# cert_path = 'path/to/certificate'
# User Input ends here.

auth = PasswordAuthenticator(username, password)

timeout_opts = ClusterTimeoutOptions(connect_timeout=timedelta(seconds=20), 
                                     kv_timeout=timedelta(seconds=20))

cluster = Cluster('couchbases://{}'.format(endpoint),
                  ClusterOptions(auth, timeout_options=timeout_opts))
cb = cluster.bucket(bucket_name)
cb_coll = cb.scope('inventory').collection('airline')
# get a reference to the default collection, required for older Couchbase server versions
cb_coll_default = cb.default_collection()

Use of newer Configuration Profile feature (we currently have one geared specifically to WAN development).

# needed for any cluster connection
from couchbase.auth import PasswordAuthenticator
from couchbase.cluster import Cluster

# needed for options -- cluster, timeout, SQL++ (N1QL) query, etc.
from couchbase.options import (ClusterOptions,
                               KnownConfigProfiles,
                               QueryOptions)

# Update this to your cluster
endpoint = '--your-instance--.dp.cloud.couchbase.com'
username = 'username'
password = 'password'
bucket_name = 'bucketname'
# not needed w/ 4.x SDK
# cert_path = 'path/to/certificate'
# User Input ends here.

auth = PasswordAuthenticator(username, password)
opts = ClusterOptions.create_options_with_profile(auth, KnownConfigProfiles.WanDevelopment)

cluster = Cluster('couchbases://{}'.format(endpoint), opts)
cb = cluster.bucket(bucket_name)
cb_coll = cb.scope('inventory').collection('airline')
# get a reference to the default collection, required for older Couchbase server versions
cb_coll_default = cb.default_collection()

This didn’t work, getting the same issue.

Hi @plmsmansit - Could you provided more information? The following is usually a helpful start:

  • Provide the version of the Python SDK are you using
  • Provide details on your environment (Operating System, Python Version, etc)
  • Provide a small code example that demonstrates the issue
  • Provide DEBUG level logs of the issue. If using SDK 4.1.0, you should be able to run the following command (using your script). If using an earlier version, see the logging docs for setup.
PYCBC_LOG_LEVEL=debug python3 <your script>.py

Python SDK = 4.1.0
OS Edition- Windows 10 Pro OS Version - 21H2

Code Snippet

auth = PasswordAuthenticator(username, password)

timeout_opts = ClusterTimeoutOptions(connect_timeout=timedelta(seconds=20),
kv_timeout=timedelta(seconds=20))

cluster = Cluster(‘couchbases://{}’.format(endpoint),
ClusterOptions(auth, timeout_options=timeout_opts))

cluster.wait_until_ready(timedelta(seconds=5))

cb = cluster.bucket(bucket_name)

Error

@plmsmansit Could you please share the debug logs? The error message you posted above is standard error, not the debug logs.

You can do it using
set PYCBC_LOG_LEVEL=debug python3 comm.py

I am getting the same UnambiguousTimeoutException, while trying to connect to a remote CB Cluster (autonomous operator):

<ec=14, category=couchbase.common, message=unambiguous_timeout (14), C Source=/Users/couchbase/jenkins/workspace/python/sdk/python-scripted-build-pipeline/py-client/src/connection.cxx:199>

debug.log on the POD shows:

[ns_server:debug,ns_1@couchbase-operator.couchbase-operator.couchbase.svc:ns_audit<0.1772.0>:ns_audit:handle_call:148]Audit auth_failure: [{local,{[{ip,<<“x.x.x.x”>>},{port,8091}]}},
{remote,{[{ip,<<“x.x.x.x”>>},{port,41186}]}},
{real_userid,{[{domain,rejected},
{user,<<“username”>>}]}},
{timestamp,<<“…”>>},
{raw_url,<<“/pools/default”>>}]

I’am however able to connect to a local docker container CB instance using the same code. Am I missing something ?

Thanks