Skip to content

nacos服务发现python SDK和curl获取的内容不一致 #318

@Young-LLL-6130

Description

@Young-LLL-6130

nacos version: nacos-server-3.2.0
nacons-python-sdk version: 3.0.4

描述:nacos python sdk通过调用list_instances接口获取的结果有问题,不是实际的注册结果;通过curl查询的结果是准确的,和前端页面显示一致,且是实际的注册结果

============================ python sdk服务获取结果 ========================
python代码:
instances = await self.naming_client.list_instances(
ListInstanceParam(service_name='auth_service', healthy_only=None))

print(f"Get instances of {NACOS_DATA_ID}: {instances}\n")

运行结果:
(venv) root@debian12:/usr/local/src/nacos-python# python3 main.py
INFO: Started server process [2885]
INFO: Waiting for application startup.
Service auth_service registered to Nacos
No config found in Nacos
Discovered services: count=1 services=['auth_service']

Get specific services: name='auth_service' groupName='DEFAULT_GROUP' clusters='' cacheMillis=10000 hosts=[Instance(instanceId='192.168.1.87#8021#DEFAULT#DEFAULT_GROUP@@auth_service', ip='192.168.1.87', port=8021, weight=1.0, healthy=True, enabled=True, ephemeral=True, clusterName='DEFAULT', serviceName='DEFAULT_GROUP@@auth_service', metadata={'a': 'b'})] lastRefTime=1776406673165 checksum='' allIps=False reachProtectionThreshold=False jsonFromServer=''

Get instances of auth_service: [Instance(instanceId='192.168.1.87#8021#DEFAULT#DEFAULT_GROUP@@auth_service', ip='192.168.1.87', port=8021, weight=1.0, healthy=True, enabled=True, ephemeral=True, clusterName='DEFAULT', serviceName='DEFAULT_GROUP@@auth_service', metadata={'a': 'b'})]

INFO: Application startup complete.
INFO: Uvicorn running on http://0.0.0.0:8001 (Press CTRL+C to quit)

============================ curl 服务获取结果 ========================
root@debian12:/usr/local/src/nacos# curl -X GET 'http://192.168.1.87:8848/nacos/v3/client/ns/instance/list?serviceName=auth_service'
{"code":0,"message":"success","data":[{"instanceId":"192.168.1.87#8021#DEFAULT#DEFAULT_GROUP@@auth_service","ip":"192.168.1.87","port":8021,"weight":1.0,"healthy":true,"enabled":true,"ephemeral":true,"clusterName":"DEFAULT","serviceName":"DEFAULT_GROUP@@auth_service","metadata":{"c":"d"},"instanceHeartBeatInterval":5000,"instanceHeartBeatTimeOut":15000,"ipDeleteTimeout":30000}]}root@debian12:/usr/local/src/nacos#
root@debian12:/usr/local/src/nacos#

============================ 前端显示结果 ========================

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions