Issue in connecting to DB for acouchbase

I am using couchbase 3.0.10 SDK on windows
Python 3.8.10

import asyncio
from acouchbase.cluster import Cluster
from couchbase.cluster import ClusterOptions, PasswordAuthenticator
CB_APPS_USER=“cb-user”
CB_APPS_PASSWORD=“Password!123”
CB_URL=“couchbase://127.0.0.1”
CB_INSTANCE=“travel-sample”

async def main():
auth = PasswordAuthenticator(CB_APPS_USER, CB_APPS_PASSWORD)
cluster = Cluster(CB_URL,options=ClusterOptions(auth))
bucket = cluster.bucket(CB_INSTANCE)
await bucket.on_connect()
r = await bucket.get(“doc::12346”)
print(r.value)
asyncio.run(main())

running main through get_event_loop works fine, asyncio having issue

loop = get_event_loop()
rv = loop.run_until_complete(main())

Traceback (most recent call last):
File “D:\project\venv\lib\site-packages\acouchbase\asyncio_iops.py”, line 78, in update_event
self.loop.remove_reader(event.fd)
File “d:\users\pachari\appdata\local\programs\python\python38\lib\asyncio\events.py”, line 504, in remove_reader
raise NotImplementedError
couchbase.exceptions.InternalSDKException: <Couldn’t invoke IO Function, inner_cause=, C Source=(src/iops.c,443)>

The above exception was the direct cause of the following exception:

SystemError: PyEval_EvalFrameEx returned a result with an error set

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File “d:/FliptRx/b2b-claim-processor-api/dbtest.py”, line 18, in
asyncio.run(main())
File “d:\users\pachari\appdata\local\programs\python\python38\lib\asyncio\runners.py”, line 44, in run
return loop.run_until_complete(main)
File “d:\users\pachari\appdata\local\programs\python\python38\lib\asyncio\base_events.py”, line 616, in run_until_complete
return future.result()
File “d:/FliptRx/b2b-claim-processor-api/dbtest.py”, line 13, in main
cluster = Cluster(CB_URL,options=ClusterOptions(auth))
File “D:\project\venv\lib\site-packages\acouchbase\cluster.py”, line 102, in init
super(ACluster, self).init(connection_string=connection_string, *options, bucket_factory=Bucket, **kwargs)
File “D:\project\venv\lib\site-packages\acouchbase\cluster.py”, line 54, in init
super(AIOClientMixin, self).init(IOPS(loop), *args, **kwargs)
File “D:\project\venv\lib\site-packages\couchbase_core\asynchronous\client.py”, line 151, in init
super(AsyncClientMixin, self).init(*args, **kwargs)
File “D:\project\venv\lib\site-packages\couchbase\cluster.py”, line 444, in init
super(Cluster, self).init(connection_string=str(self.connstr), _conntype=_LCB.LCB_TYPE_CLUSTER, **self._clusteropts)
File “D:\project\venv\lib\site-packages\couchbase_core\client.py”, line 159, in init
self._do_ctor_connect()
File “D:\project\venv\lib\site-packages\couchbase\cluster.py”, line 464, in _do_ctor_connect
super(Cluster,self)._do_ctor_connect(*args,**kwargs)
File “D:\project\venv\lib\site-packages\couchbase_core\client.py”, line 168, in _do_ctor_connect
self._connect()
SystemError: <method ‘_connect’ of ‘Client’ objects> returned a result with an error set
Exception ignored in tp_clear of: <class ‘SystemError’>
Traceback (most recent call last):
File “D:\project\venv\lib\site-packages\couchbase\exceptions.py”, line 155, in init
File “D:\project\venv\lib\site-packages\couchbase\exceptions.py”, line 605, in from_dict
KeyError: ‘couchbase.exceptions’
(venv) PS D:\project> & d:/FliptRx/b2b-claim-processor-api/venv/Scripts/python.exe d:/FliptRx/b2b-claim-processor-api/dbtest.py
Traceback (most recent call last):
File “D:\project\venv\lib\site-packages\acouchbase\asyncio_iops.py”, line 78, in update_event
self.loop.remove_reader(event.fd)
File “d:\users\pachari\appdata\local\programs\python\python38\lib\asyncio\events.py”, line 504, in remove_reader
raise NotImplementedError
couchbase.exceptions.InternalSDKException: <Couldn’t invoke IO Function, inner_cause=, C Source=(src/iops.c,443)>

The above exception was the direct cause of the following exception:

SystemError: PyEval_EvalFrameEx returned a result with an error set

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File “d:/FliptRx/b2b-claim-processor-api/dbtest.py”, line 17, in
asyncio.run(main())
File “d:\users\pachari\appdata\local\programs\python\python38\lib\asyncio\runners.py”, line 44, in run
return loop.run_until_complete(main)
File “d:\users\pachari\appdata\local\programs\python\python38\lib\asyncio\base_events.py”, line 616, in run_until_complete
return future.result()
File “d:/FliptRx/b2b-claim-processor-api/dbtest.py”, line 11, in main
cluster = Cluster(CB_URL,options=ClusterOptions(auth))
File “D:\project\venv\lib\site-packages\acouchbase\cluster.py”, line 102, in init
super(ACluster, self).init(connection_string=connection_string, *options, bucket_factory=Bucket, **kwargs)
File “D:\project\venv\lib\site-packages\acouchbase\cluster.py”, line 54, in init
super(AIOClientMixin, self).init(IOPS(loop), *args, **kwargs)
File “D:\project\venv\lib\site-packages\couchbase_core\asynchronous\client.py”, line 151, in init
super(AsyncClientMixin, self).init(*args, **kwargs)
File “D:\project\venv\lib\site-packages\couchbase\cluster.py”, line 444, in init
super(Cluster, self).init(connection_string=str(self.connstr), _conntype=_LCB.LCB_TYPE_CLUSTER, **self._clusteropts)
File “D:\project\venv\lib\site-packages\couchbase_core\client.py”, line 159, in init
self._do_ctor_connect()
File “D:\project\venv\lib\site-packages\couchbase\cluster.py”, line 464, in _do_ctor_connect
super(Cluster,self)._do_ctor_connect(*args,**kwargs)
File “D:\project\venv\lib\site-packages\couchbase_core\client.py”, line 168, in _do_ctor_connect
self._connect()
SystemError: <method ‘_connect’ of ‘Client’ objects> returned a result with an error set
Exception ignored in tp_clear of: <class ‘SystemError’>
Traceback (most recent call last):

Hi @achari.prashant – Is there a reason you are using a very old version (3.0.10) of the SDK? There was a decent amount of work done in the acouchbase API in later versions. My suggestion is to use the 4.x version of the SDK, but if you cannot move to the 4.x version, try to use the latest 3.x version of the SDK (3.2.7).

Also, because we do not define an event loop policy, you need to first get the event loop and then use the loop to execute. I think you are saying you have issues with asyncio.run() which I would expect.

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