Asynchronous N1QL does not work

Hi!
I am trying to use async API of Couchbase. I have following code :

from couchbase.exceptions import (
    CouchbaseException, DocumentNotFoundException, ParsingFailedException)


from acouchbase.cluster import get_event_loop

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


async def get_couchbase():
    cluster = Cluster(
        "http://localhost:8091/",
        ClusterOptions(PasswordAuthenticator("admin", "password")))
    bucket = cluster.bucket("travel-sample")
    await bucket.on_connect()

    return cluster, bucket


async def n1ql_query(cluster):
    try:
        result = cluster.query(
            "SELECT * FROM `travel-sample` LIMIT 10")

        async for row in result:
            print("Found row: {}".format(row))
    except ParsingFailedException as ex:
        print(ex)
    except CouchbaseException as ex:
        print(ex)



loop = get_event_loop()
cluster, bucket = loop.run_until_complete(get_couchbase())

cb_coll_default = bucket.default_collection()

loop.run_until_complete(n1ql_query(cluster))

However, I constantly get such mistake:

I use Couchbase Community Edition 7.0.0 , SDK 3.2.5 and Python 3.9

couchbase.exceptions.InvalidArgumentException: <RC=0xCB[LCB_ERR_INVALID_ARGUMENT (203)], Couldn't create instance. Either bad credentials/hosts/bucket names were passed, or there was an internal error in creating the object, C Source=(src/bucket.c,1116)>

What am I doing wrong?

Hi @Kessler2009 - Can you try changing the connection string and awaiting the cluster connection? Snippet below.

async def get_couchbase():
    cluster = Cluster(
        "couchbase://localhost",
        ClusterOptions(PasswordAuthenticator("admin", "password")))
    await cluster.on_connect()
    bucket = cluster.bucket("travel-sample")
    await bucket.on_connect()
    return cluster, bucket
1 Like

That worked. Thanks!