skip to Main Content

I have written a couchbase code, which is working absoulutely fine when I am running it in my local, but when I am trying to create the docker image, I am getting the error.

Python SDK Code:

from config import config
import base64
from couchbase.cluster import Cluster
from couchbase.options import (ClusterOptions,
                               ClusterTimeoutOptions,
                               QueryOptions,
                               WaitUntilReadyOptions)
from couchbase.auth import PasswordAuthenticator
from datetime import timedelta
from couchbase.diagnostics import ServiceType

def query_couchbase(n1ql_query):
        conn_str = config.CLUSTER_CONN_STR
        cb_username = config.CB_USERNAME
        cb_password = config.CB_PASSWORD
        cb_password = base64.b64decode(cb_password.encode('utf-8')).decode('utf-8')
        bucket_name = config.BUCKET_NAME
        auth = PasswordAuthenticator(cb_username, cb_password)
        timeout_opts = ClusterTimeoutOptions(connect_timeout=timedelta(seconds=20),
                                            kv_timeout=timedelta(seconds=20))
        options = ClusterOptions(auth, timeout_options=timeout_opts)
        options = ClusterOptions(auth)
        cluster = Cluster.connect(conn_str, options)
        cluster.wait_until_ready(timedelta(seconds=10),
                                WaitUntilReadyOptions(service_types=[ServiceType.KeyValue, ServiceType.Query]))
        cluster.bucket(bucket_name)
        query_result = cluster.query(n1ql_query)
        return query_result

requirements.txt:

pyJWT~=2.6.0
requests~=2.28.1
urllib3==1.26.6
zipfile36
fastapi~=0.88.0
promise~=2.3
azure-storage-blob==12.14.1
uvicorn
starlette~=0.22.0
httpx~=0.23.1
pydantic~=1.10.2

openai 
num2words 
pandas 
plotly 
tiktoken 
config
python-multipart
nltk
psycopg2-binary

Docker File:

FROM python:3.9-slim
WORKDIR /code
RUN apt-get update 
RUN apt-get install -y  
    libssl1.1 
    fonts-liberation 
    libasound2 
    libatk-bridge2.0-0 
    libatk1.0-0 
    libatspi2.0-0 
    libcups2 
    libdbus-1-3 
    libdrm2 
    libgbm1 
    libgtk-3-0 
    libnspr4 
    libnss3 
    libwayland-client0 
    libxcomposite1 
    libxdamage1 
    libxfixes3 
    libxkbcommon0 
    libxrandr2 
    xdg-utils 
    libu2f-udev 
    libvulkan1
RUN apt-get install --no-install-suggests --no-install-recommends --yes .gyp python3 make g++
COPY ./requirements.txt ./requirements.txt
RUN pip install --upgrade pip
RUN pip install -r ./requirements.txt
RUN pip install -U scikit-learn scipy matplotlib
RUN pip install couchbase
RUN pip install pyOpenSSL
RUN rm -rf .gyp
COPY ./app /code/app
EXPOSE 8080
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8080"]

Docker image is getting creating but while running the image I am getting the below error from couchbase import statement:

terminate called after throwing an instance of 'std::bad_cast'
  what():  std::bad_cast

2

Answers


  1. Chosen as BEST ANSWER

    The problem remains unidentified, but I managed to resolve it by isolating the Couchbase code and making the services accessible through endpoints. It appears that there might be a conflict between the Couchbase and OpenAI library, as the latter worked smoothly with other libraries. The root cause of the issue lies within the Couchbase Python SDK, which conflicts with certain libraries, one of which is OpenAI, as I have recently discovered.


  2. we’ve seen a few rare cases of this and usually is related to sounds importing another library with C/C++ extensions (though that does not appear in the snippet they provided). There is a PYCBC about it: https://issues.couchbase.com/browse/PYCBC-1495

    Similar issues (not Couchbase):
    https://github.com/carla-simulator/carla/issues/1125
    Importing two shared libraries which uses C++ streams into python results in corrupted output

    Can you provide a bit more of the error output? There should be mention of which library it is failing the import of.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search