Consider following piece of code:
import asyncio
from acouchbase.cluster import Cluster
from couchbase.cluster import ClusterOptions
from couchbase.cluster import PasswordAuthenticator
async def do_crud_op():
cb = Cluster.connect("couchbase://localhost", options=ClusterOptions(PasswordAuthenticator("user", "password")))
cb = cb.bucket('customers')
await cb.upsert('id', {'some': 'value'})
return await cb.get('id')
loop = asyncio.get_event_loop()
rv = loop.run_until_complete(do_crud_op())
print(rv.value)
I am using Python 3.0 SDK and COuchbase 6.5.1 on Ubuntu 20.04. The above code gives me LCB_ERR_NO_CONFIGURATION
exception. Can someone help?
Well, I found out that we need to wait on bucket variable using on_connect
method to make it work.
import asyncio
from acouchbase.cluster import Cluster
from couchbase.cluster import ClusterOptions
from couchbase.cluster import PasswordAuthenticator
async def do_crud_op():
cb = Cluster.connect("couchbase://localhost", options=ClusterOptions(PasswordAuthenticator("user", "password")))
cb = cb.bucket('customers')
await cb.on_connect()
await cb.upsert('id', {'some': 'value'})
return await cb.get('id')
loop = asyncio.get_event_loop()
rv = loop.run_until_complete(do_crud_op())
print(rv.value)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.