Skip to content
Advertisement

Select query is working but insert query is not in Python with Couchbase library

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

Advertisement

Answer

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

Advertisement