1

I'm trying to do some remote operations with Couchbase Python library. I have written a small code piece to test if it is working as intended.

server_name = 'xxxxxxxxxx'
bucket_name = 'vit_app_clob'
username = "Administrator"
password = "xxxxxx"
json_path = 'D:\\' + bucket_name + '_' + server_name + '.json'

cluster = Cluster('couchbase://' + server_name + ':8091', ClusterOptions(PasswordAuthenticator(username, password)))

bucket = cluster.bucket(bucket_name)


def insert(bucket):
    result = cluster.query("INSERT INTO `oracle_test`(KEY, VALUE) VALUES ('key1', { 'type' : 'hotel', 'name' : 'new hotel' })")


def select():
    result = cluster.query('SELECT * FROM ' + bucket_name)
    myDict = []

    for row in result:
        name = row[bucket_name]
        # print(name)
        myDict.append(name)

    df = pd.DataFrame(myDict)
    with open(json_path, "w") as f:
        json.dump(myDict, f, indent=1)


select()
# insert(bucket)

Select function works well. Query runs and there is no problem. But the other one, which I'm trying to use for inserting, doesn't work. It gives a timeout error.

couchbase.exceptions.TimeoutException: <Key='key3', RC=0xC9[LCB_ERR_TIMEOUT (201)]

What could be the reason? The query is working when I run it in the query section of couchbase interface.

Edit: There is this part in error log: 'endpoint': 'xxxxxx:11210'. Do I need to have an open connection in this port? It seems I don't have any access right now, since the telnet is not working. If this is the case, that means connecting via 8091 is not enough?

Edit2: We opened connection to port but the same problem exists

  • 1
    Why don't you try `bucket.insert` method? For example: `bucket.insert('key1', { 'type' : 'hotel', 'name' : 'new hotel' })` as documented in https://docs.couchbase.com/python-sdk/2.5/document-operations.html#creating-and-updating-full-documents – stuck Feb 25 '22 at 13:21
  • Probably you need to commit to write the data into the db. – ThoPaz Feb 25 '22 at 13:21
  • I've also tried that @stuck. It gives the same timeout error :/ – Bünyamin Şentürk Feb 25 '22 at 13:23
  • 1
    I would agree with @stuck that if you are inserting/updating a single document, favor the key/value interface (`bucket.insert` in older versions, `collection.insert` in the latest versions), since using an `INSERT` query will invoke some unnecessary overhead. – Matthew Groves Feb 25 '22 at 14:43

2 Answers2

2

You are correct in that port 8091 is generally not enough. Check out the documentation on Couchbase port numbers.

You may not need all those ports, depending on which services you're using, but for my day-to-day work, I usually open ports 8091-8097 and 11210. (There are counterpart ports for encrypted traffic).

Matthew Groves
  • 25,181
  • 9
  • 71
  • 121
0

I don't even know why, but adding .execute() to end of the query solved the problem. SELECT query was already working without it. Also, I needed to open a connection on port 11210