Python SDK 3.0 Sample Code results in issues on query

the starter Code form Python SDK Docs throw an error for an “open Bucket” and Network Exceptions.
Code:

from couchbase.cluster import Cluster, ClusterOptions, QueryOptions
from couchbase_core.cluster import PasswordAuthenticator

cluster = Cluster('couchbase://CouchbaseServer.com', ClusterOptions(PasswordAuthenticator('username', 'password')))
cb = cluster.bucket('app')
cb_coll = cb.default_collection()

#cluster.query_indexes().create_primary_index('app')

row_iter = cluster.query('SELECT name FROM app WHERE $1 IN interests', QueryOptions(positional_parameters=['African Swallows']))
for row in row_iter: print(row)

Error :

Traceback (most recent call last):
  File "/home/vm/text1.py", line 10, in <module>
    row_iter = cluster.query('SELECT name FROM app WHERE $1 IN interests', QueryOptions(positional_parameters=['African Swallows']))
  File "/home/vm/.local/lib/python3.6/site-packages/couchbase/cluster.py", line 609, in query
    err_msg="Query requires an open bucket")
  File "/home/vm/.local/lib/python3.6/site-packages/couchbase/cluster.py", line 624, in _maybe_operate_on_an_open_bucket
    if self._is_6_5_plus():
  File "/home/vm/.local/lib/python3.6/site-packages/couchbase/cluster.py", line 555, in _is_6_5_plus
    response = self._admin.http_request(path="/pools").value
  File "/home/vm/.local/lib/python3.6/site-packages/couchbase/management/admin.py", line 165, in http_request
    timeout=timeout)
couchbase.exceptions.TimeoutException: <Key='/pools', RC=0xC9[LCB_ERR_TIMEOUT (201)], HTTP Request failed. Examine 'objextra' for full result, Results=1, C Source=(src/pycbc_http.c,212), OBJ=HttpResult<rc=0xC9[LCB_ERR_TIMEOUT (201)], value=None, http_status=0, url=/pools, tracing_context=0, tracing_output=None>, Context={'response_code': 0, 'path': '/pools', 'response_body': '', 'endpoint': 'CouchbaseServer.com:8091', 'type': 'HTTPErrorContext'}, Tracing Output={":nokey:0": null}>

I read the python SDK docs for this but didnt find anything which can help to solve this error.
The Document already exists in bucket on Server. Also i cant use CRUD operations.
Whats causing this?

Environment:
ubuntu 18 64-bit
Python 3.6.9
Couchbase Server 6.5 CE
Python SDK 3.0

Also if im creating an index while the script

Could someone point me out how to solved it or any Docs that can work.
thank you

Hi, looks like a connectivity issue on the Admin port - we fixed an issue similar to this recently. Are you using the latest SDK (3.0.3)?

If you have upgraded to 3.0.3 and this still happens, please could you collect libcouchbase logs as described here:

https://docs.couchbase.com/python-sdk/3.0/howtos/collecting-information-and-logging.html

You will also need to set LCB_LOGLEVEL to greater than 0 - I would suggest 5:

export LCB_LOGLEVEL=5 # for POSIX
set LCB_LOGLEVLEL=5 # for Windows

yes im using couchbase 3.0.3 installed by pip

OK - please try the diagnostics as described above. Thanks!

This may be due to bootstrapping for services taking longer than for KV. We are working on a solution to this (Cluster.wait_until_ready), but in the meantime, could you attempt to retry the query operation a few times, like so?

deadline=datetime.now()+timedelta(seconds=60) # 60 seconds is an example, but should be more than enough time
while True:
    try:
        cluster.query(...)
        break
    except TimeoutException:
        if datetime.now()>=deadline:
            raise
        time.sleep(5) # don't hammer the server too hard

Cluster.wait_until_ready should simplify this. We chose to expose the asynchronous nature of connection for SDK3, as in practice connections may drop, so it is always a good idea to handle the possibility that the server might not be up.

Sorry but this solution is not working the connection does happen to the server but the query results in TimeoutException , also

  1. why does the query throws an err_msg="Query requires an open bucket"
  2. Is there a way to configure the ports in sdk 3