I am getting the following error from a python script that first starts a couchbase instance in docker and then tries to connect to the couchbase database.
The python couchbase connection works just fine if I already have the container up separately but the code throws a connection error if it tries to start the docker couchbase container and connection in the same python script.
Here's the error
Traceback (most recent call last):
File "/Users/APatel/Documents/playground/exapp/cb_connect_example.py", line 38, in <module>
cluster = Cluster('couchbase://localhost', ClusterOptions(authenticator))
File "/Users/APatel/.local/share/virtualenvs/exapp-oN-J56Zb/lib/python3.6/site-packages/couchbase/cluster.py", line 490, in __init__
super(Cluster, self).__init__(connection_string=str(self.connstr), _conntype=_LCB.LCB_TYPE_CLUSTER, **self._clusteropts)
File "/Users/APatel/.local/share/virtualenvs/exapp-oN-J56Zb/lib/python3.6/site-packages/couchbase_core/client.py", line 159, in __init__
self._do_ctor_connect()
File "/Users/APatel/.local/share/virtualenvs/exapp-oN-J56Zb/lib/python3.6/site-packages/couchbase/cluster.py", line 510, in _do_ctor_connect
super(Cluster,self)._do_ctor_connect(*args,**kwargs)
File "/Users/APatel/.local/share/virtualenvs/exapp-oN-J56Zb/lib/python3.6/site-packages/couchbase_core/client.py", line 168, in _do_ctor_connect
self._connect()
couchbase.exceptions.LCB_0x401 (generated, catch: BaseException, KeyValueException, AnalyticsException, ViewException): <RC=0x401[LCB_ERR_SOCKET_SHUTDOWN (1025)], There was a problem while trying to send/receive your request over the network. This may be a result of a bad network or a misconfigured client or server, C Source=(src/bucket.c,1209)>
And here's the python code.
from couchbase.cluster import Cluster, ClusterOptions
from couchbase_core.cluster import PasswordAuthenticator
import docker
import time
client = docker.from_env()
def remove_e2e_container():
docker_containers = client.containers.list()
for container in docker_containers:
if container.name == 'e2e_container':
container.remove(force=True)
def create_container():
remove_e2e_container()
client.containers.run('bentonam/couchbase-docker', name='e2e_container', detach=True,
environment=["CLUSTER_RAMSIZE=500", "BUCKET_RAMSIZE=500",
"BUCKET=accums_e2e_test",
"SERVICES: data,index,query"],
ports={'8091/tcp': 8091, '8092/tcp': 8092, '8093/tcp': 8093, '8094/tcp':
8094, '11210/tcp': 11210})
create_container()
config = {
'login': 'Administrator',
'password': 'password',
'host': "couchbase://localhost",
'schema': 'accums_e2e_test'
}
authenticator = PasswordAuthenticator(config.get('login'), config.get('password'))
cluster = Cluster('couchbase://localhost', ClusterOptions(authenticator))
cb = cluster.bucket('accums_e2e_test')
results = cb.query("CREATE PRIMARY INDEX ON `accums_e2e_test`")
for i in results:
print(i)
question from:
https://stackoverflow.com/questions/65948198/python-couchbase-connection-throwing-an-error-when-trying-to-access-a-database-i