You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用pymilvus 2.2.9连接Milvus服务器时遇版本不兼容及连接超时问题

Milvus连接失败问题排查

问题情况

在Jupyter Notebook中使用pymilvus 2.2.9版本连接Milvus服务器时出现错误,此前在Colab环境中遇到grpcio相关问题,按提示降级到1.53.0后仍未解决,切换到Jupyter Notebook后依旧存在类似问题。

使用代码

# Connect to Milvus service
connections.connect(host=HOST, port=PORT)

# Create collection
collection = create_milvus_collection(COLLECTION_NAME, DIM)
print(f'A new collection created: {COLLECTION_NAME}')

报错信息

2023-06-19 03:51:10,646 - 8380245248 - decorators.py-decorators:108 - ERROR: RPC error: [__internal_register], <MilvusException: (code=1, message=this version of sdk is incompatible with server, please downgrade your sdk or upgrade your server )>, <Time:{'RPC start': '2023-06-19 03:51:10.636182', 'RPC error': '2023-06-19 03:51:10.646730'}>
---------------------------------------------------------------------------
_InactiveRpcError                         Traceback (most recent call last) File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pymilvus/decorators.py:163, in upgrade_reminder.<locals>.handler(*args, **kwargs) 162 try: 163     return func(*args, **kwargs) 164 except grpc.RpcError as e:

File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pymilvus/client/grpc_handler.py:1359, in GrpcHandler.__internal_register(self, user, host) 1358 req = Prepare.register_request(user, host) 1359 response = self._stub.Connect(request=req) 1360 if response.status.error_code != common_pb2.Success:

File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/grpc/_interceptor.py:247, in _UnaryUnaryMultiCallable.__call__(self, request, timeout, metadata, credentials, wait_for_ready, compression) 240 def __call__(self, 241              request: Any, 242              timeout: Optional[float] = None,    (...) 245              wait_for_ready: Optional[bool] = None, 246              compression: Optional[grpc.Compression] = None) -> Any: 247     response, ignored_call = self._with_call(request, 248                                              timeout=timeout, 249                                              metadata=metadata, 250                                              credentials=credentials, 251                                              wait_for_ready=wait_for_ready, 252                                              compression=compression) 253     return response

File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/grpc/_interceptor.py:290, in _UnaryUnaryMultiCallable._with_call(self, request, timeout, metadata, credentials, wait_for_ready, compression) 287 call = self._interceptor.intercept_unary_unary(continuation, 288                                                client_call_details, 289                                                request) 290 return call.result(), call

File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/grpc/_channel.py:379, in _InactiveRpcError.result(self, timeout) 378 """See grpc.Future.result.""" 379 raise self

File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/grpc/_interceptor.py:274, in _UnaryUnaryMultiCallable._with_call.<locals>.continuation(new_details, request) 273 try: 274     response, call = self._thunk(new_method).with_call( 275         request, 276         timeout=new_timeout, 277         metadata=new_metadata, 278         credentials=new_credentials, 279         wait_for_ready=new_wait_for_ready, 280         compression=new_compression) 281     return _UnaryOutcome(response, call)

File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/grpc/_channel.py:1043, in _UnaryUnaryMultiCallable.with_call(self, request, timeout, metadata, credentials, wait_for_ready, compression) 1041 state, call, = self._blocking(request, timeout, metadata, credentials, 1042                               wait_for_ready, compression) 1043 return _end_unary_response_blocking(state, call, True, None)

File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/grpc/_channel.py:910, in _end_unary_response_blocking(state, call, with_call, deadline) 909 else: 910     raise _InactiveRpcError(state)

_InactiveRpcError: <_InactiveRpcError of RPC that terminated with:  status = StatusCode.UNIMPLEMENTED   details = "unknown method Connect for service milvus.proto.milvus.MilvusService"    debug_error_string = "UNKNOWN:Error received from peer ipv4:127.0.0.1:19530 {created_time:"2023-06-19T03:51:10.642309+05:30", grpc_status:12, grpc_message:"unknown method Connect for service milvus.proto.milvus.MilvusService"}"
>

The above exception was the direct cause of the following exception:

MilvusException                           Traceback (most recent call last) File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pymilvus/client/grpc_handler.py:120, in GrpcHandler._wait_for_channel_ready(self, timeout) 119 grpc.channel_ready_future(self._channel).result(timeout=timeout) 120 self._setup_identifier_interceptor(self._user) 121 return

File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pymilvus/client/grpc_handler.py:220, in GrpcHandler._setup_identifier_interceptor(self, user) 219 host = socket.gethostname() 220 self._identifier = self.__internal_register(user, host) 221 self._identifier_interceptor = interceptor.header_adder_interceptor(["identifier"], [str(self._identifier)])

File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pymilvus/decorators.py:109, in error_handler.<locals>.wrapper.<locals>.handler(*args, **kwargs) 108     LOGGER.error(f"RPC error: [{inner_name}], {e}, <Time:{record_dict}>") 109     raise e 110 except grpc.FutureTimeoutError as e:

File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pymilvus/decorators.py:105, in error_handler.<locals>.wrapper.<locals>.handler(*args, **kwargs) 104     record_dict["RPC start"] = str(datetime.datetime.now()) 105     return func(*args, **kwargs) 106 except MilvusException as e:

File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pymilvus/decorators.py:136, in tracing_request.<locals>.wrapper.<locals>.handler(self, *args, **kwargs) 135     self.set_onetime_request_id(req_id) 136 ret = func(self, *args, **kwargs) 137 return ret

File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pymilvus/decorators.py:85, in retry_on_rpc_failure.<locals>.wrapper.<locals>.handler(self, *args, **kwargs) 84     else: 85         raise e 86 except Exception as e:

File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pymilvus/decorators.py:50, in retry_on_rpc_failure.<locals>.wrapper.<locals>.handler(self, *args, **kwargs) 49 try: 50     return func(self, *args, **kwargs) 51 except grpc.RpcError as e: 52     # DEADLINE_EXCEEDED means that the task wat not completed 53     # UNAVAILABLE means that the service is not reachable currently 54     # Reference: https://grpc.github.io/grpc/python/grpc.html#grpc-status-code

File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pymilvus/decorators.py:168, in upgrade_reminder.<locals>.handler(*args, **kwargs) 166     msg = "this version of sdk is incompatible with server, please downgrade your sdk or upgrade your " \ 167           "server " 168     raise MilvusException(message=msg) from e 169 raise e

MilvusException: <MilvusException: (code=1, message=this version of sdk is incompatible with server, please downgrade your sdk or upgrade your server )>

The above exception was the direct cause of the following exception:

MilvusException                           Traceback (most recent call last) Cell In[7], line 2 1 # Connect to Milvus service 2 connections.connect(host=HOST, port=PORT) 4 # Create collection 5 collection = create_milvus_collection(COLLECTION_NAME, DIM)

File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pymilvus/orm/connections.py:349, in Connections.connect(self, alias, user, password, db_name, token, **kwargs) 345         if parsed_uri.scheme == "https": 346             kwargs["secure"] = True 349     connect_milvus(**kwargs, user=user, password=password, token=token, db_name=db_name) 350     return 352 # 2nd Priority, connection configs from env

File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pymilvus/orm/connections.py:282, in Connections.connect.<locals>.connect_milvus(**kwargs) 279 t = kwargs.get("timeout") 280 timeout = t if isinstance(t, (int, float)) else Config.MILVUS_CONN_TIMEOUT 282 gh._wait_for_channel_ready(timeout=timeout) 283 kwargs.pop('password') 284 kwargs.pop("token", None)

File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pymilvus/client/grpc_handler.py:123, in GrpcHandler._wait_for_channel_ready(self, timeout) 121         return 122     except (grpc.FutureTimeoutError,  MilvusException) as e: 123         raise MilvusException(Status.CONNECT_FAILED, 124                               f'Fail connecting to server on {self._address}. Timeout') from e 126 raise MilvusException(Status.CONNECT_FAILED, 'No channel in handler, please setup grpc channel first')

MilvusException: <MilvusException: (code=2, message=Fail connecting to server on 127.0.0.1:19530. Timeout)

解决建议

  • 版本兼容性检查:报错核心提示SDK与服务器版本不兼容,Milvus要求pymilvus主版本号必须和服务器一致,次版本号可低于或等于服务器。先查看Milvus服务器版本(通过控制台或执行milvus-server --version),再安装对应版本的pymilvus。例如服务器是2.1.x,就将pymilvus降级到2.1.x系列。
  • 修复grpcio依赖:卸载现有grpcio和grpcio-tools,重新安装与pymilvus 2.2.9兼容的版本(推荐1.56.0):
    pip uninstall -y grpcio grpcio-tools
    pip install grpcio==1.56.0 grpcio-tools==1.56.0
    
  • 验证服务器连通性:确保Milvus服务器正在运行,端口19530开放。本地可执行telnet 127.0.0.1 19530或nc -zv 127.0.0.1 19530测试连接。
  • 清理缓存重装:若问题仍存在,清理pip缓存后重新安装pymilvus:
    pip cache purge
    pip install pymilvus==2.2.9 --no-cache-dir
    

内容的提问来源于stack exchange,提问作者akash

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.18 17:02:00