使用LlamaIndex向Pinecone DB导入数据时遇SSL重试超限错误求助
LlamaIndex向Pinecone导入数据时的SSL连接错误排查与解决建议
错误现象
URL请求重试次数超限:
(Caused by SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:2427)')))
详细错误栈
LlamaIndex_Doc_Helper-JJYEcwwZ\Lib\site-packages\urllib3\util\retry.py", line 515, in increment raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='llamaindex-documentation-helper-ksad0bm.svc.gcp-starter.pinecone.io', port=443): Max retries exceeded with url: /vectors/upsert (Caused by SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:2427)'))) Upserted vectors: 0%| | 0/18 [00:02<?, ?it/s]
使用的Python代码
#--- Indexing in Pinecone # Init. Pinecone Index object index_name = "llamaindex-documentation-helper" pinecone_index = pinecone.Index(index_name=index_name) # Init. vector store object vector_store = PineconeVectorStore(pinecone_index=pinecone_index) # Init storage context storage_context = StorageContext.from_defaults(vector_store=vector_store) # Creates index = VectorStoreIndex.from_documents( documents=documents, # documents = dir_reader.load_data() storage_context=storage_context, # storage_context = StorageContext.from_defaults(vector_store=vector_store) service_context=service_context, # service_context = ServiceContext.from_defaults(llm=llm, embed_model=embed_model, node_parser=node_parser) show_progress=True, )
已完成的排查步骤
- 关闭防火墙、VPN和杀毒软件
- 系统:Windows 11 Pro
- Python环境:3.12版本(pipenv管理)
- 已升级certifi至最新版本
- 可正常ping通服务器:
LlamaIndex Tutorial\LlamaIndex Doc Helper> ping llamaindex-documentation-helper-ksad0bm.svc.gcp-starter.pinecone.io Pinging ingress.gcp-starter.pinecone.io [34.160.88.44] with 32 bytes of data: Reply from 34.160.88.44: bytes=32 time=10ms TTL=114 Reply from 34.160.88.44: bytes=32 time=9ms TTL=114 Reply from 34.160.88.44: bytes=32 time=11ms TTL=114 Reply from 34.160.88.44: bytes=32 time=9ms TTL=114 Ping statistics for 34.160.88.44: Packets: Sent = 4, Received = 4, Lost = 0 (0% loss), Approximate round trip times in milli-seconds: Minimum = 9ms, Maximum = 11ms, Average = 9ms
解决建议
- 降级Python版本:Python 3.12对SSL库的改动可能引发兼容性问题,切换到Python 3.11版本,重新构建pipenv环境后测试。
- 强制指定SSL协议版本:通过自定义HTTP客户端,强制使用TLS 1.2或1.3协议连接Pinecone。示例代码:
import pinecone import requests from requests.adapters import HTTPAdapter from urllib3.poolmanager import PoolManager import ssl class TLSAdapter(HTTPAdapter): def init_poolmanager(self, connections, maxsize, block=False): self.poolmanager = PoolManager( num_pools=connections, maxsize=maxsize, block=block, ssl_version=ssl.PROTOCOL_TLSv1_3 ) session = requests.Session() session.mount("https://", TLSAdapter()) pinecone.init(api_key="YOUR_API_KEY", environment="YOUR_ENV", session=session) pinecone_index = pinecone.Index(index_name=index_name) - 升级Pinecone客户端:执行
pip install --upgrade pinecone-client,将客户端更新至最新稳定版。 - 调整超时与重试策略:初始化Pinecone Index时延长超时时间、调整重试次数:
pinecone_index = pinecone.Index( index_name=index_name, timeout=60, # 延长超时时间至60秒 retry_config={"max_retries": 5} # 调整最大重试次数 ) - 手动指定证书路径:在代码开头添加以下内容,强制使用certifi提供的证书:
import os import certifi os.environ['SSL_CERT_FILE'] = certifi.where()
内容的提问来源于stack exchange,提问作者Alex Ricciardi
相关产品推荐
相关产品推荐

