std::bad_cast 使用 Python SDK for Couchbase 时出现错误。

huangapple go评论81阅读模式
英文:

std::bad_cast error while using Python SDK for couchbase

问题

我已经编写了一个Couchbase代码,在本地运行时完全正常,但当我尝试创建Docker镜像时,出现了错误。

Python SDK 代码:

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 文件:

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 镜像已经创建,但在运行镜像时,我从 Couchbase 导入语句处收到以下错误:

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

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

答案1

得分: 1

我们看到了一些罕见的情况,通常与导入另一个具有C/C++扩展的库相关(尽管在他们提供的代码片段中并未出现)。这方面有一个关于PYCBC的问题:https://issues.couchbase.com/browse/PYCBC-1495

类似的问题(不是Couchbase):
https://github.com/carla-simulator/carla/issues/1125
https://stackoverflow.com/questions/44577203/importing-two-shared-libraries-which-uses-c-streams-into-python-results-in-cor

你能提供一些更多的错误输出吗?应该会提到导入失败的是哪个库。

英文:

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
https://stackoverflow.com/questions/44577203/importing-two-shared-libraries-which-uses-c-streams-into-python-results-in-cor

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

答案2

得分: 1

问题仍然未被识别,但我成功通过隔离Couchbase代码并通过端点使服务可访问来解决了它。似乎Couchbase和OpenAI库之间可能存在冲突,因为后者在与其他库一起使用时表现良好。问题的根本原因在于Couchbase Python SDK,它与某些库发生冲突,其中之一就是OpenAI,我最近才发现的。

英文:

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.

huangapple
  • 本文由 发表于 2023年7月17日 23:31:21
  • 转载请务必保留本文链接:https://go.coder-hub.com/76706020.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定