Python client 4.1.6 throws an exception when trying to connect to couchbase

I’ve installed a new couchbase server and attempted to connect to it when the following python code

from couchbase.cluster import Cluster
from couchbase.auth import PasswordAuthenticator

from couchbase.options import (ClusterOptions, ClusterTimeoutOptions, QueryOptions)

print("Connection Test")

auth = PasswordAuthenticator("Administrator", "password");
cluster = Cluster("couchbase://localhost:8091", ClusterOptions(auth))

User and password is correct. I have even tested the server using curl command.

curl -u Administrator:password http://localhost:8091/pools/default

The server responds with the expected output. When I try to execute the python code I get the following error

couchdb/virtualenv3/lib/python3.8/site-packages/couchbase/cluster.py", line 105, in _connect
    raise ErrorMapper.build_exception(ret)
couchbase.exceptions.RequestCanceledException: RequestCanceledException(<ec=2, category=couchbase.common, message=request_canceled (2), C Source=/home/ec2-user/workspace/python/sdk/python-packaging-pipeline/py-client/src/connection.cxx:199>)

This is pretty much a basic hello world test and it fails. Looking for ideas on what to look into.

Python couchbase version 4.1.6
Couchbase version: Community Edition 7.1.1 build 3175
OS version: Ubuntu 20.04

Hello, welcome to the Couchbase forums!

It’s not necessary to specify a port in the connection string. If you try replacing the connection string with simply "couchbase://localhost" it should be able to connect successfully.

1 Like

Thanks that actually worked. Just curious, even though not necessary, why would the code fail? If I change the port would the new uri be couchbase://localhost:<NEW_PORT> ?

Thanks for the help!

The 4.X Python SDK uses the C++ SDK internally which connects to a cluster via the Data Service ports. You can find an overview of the ports used by Couchbase Server on this page.

8091 is the HTTP port which is why it cannot connect using that. That might change once CXXCBC-269 is implemented. If you use the Data Service (memcached) port in the connection string instead, it will be able to connect successfully (the default 11210 or the custom Data Service port if you have custom ports set up)

Ok, thanks. I understand now and will continue to follow the development.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.