实现python引用nacos的配置

[root@localhost pythondemo]# cat .env
nacos_server="127.0.0.7:80"
nacos_namespace_id="dev"
nacos_suth_user="nacos"
nacos_auth_passwd="nacos"

pip3 install nacos-sdk-python
pip3 install ConfigParser
[root@localhost pythondemo]# cat newdemo.py
import nacos
import configparser
from io import StringIO

SERVER_ADDRESSES = "http://127.0.0.1:80"
NAMESPACE = "dev"
data_id = "pythondemo"
group = "DEFAULT_GROUP"
    
client = nacos.NacosClient(SERVER_ADDRESSES, namespace=NAMESPACE)
nacos_conf = client.get_config(data_id, group)
conf = configparser.ConfigParser()
conf.readfp(StringIO(nacos_conf))
url = conf.get("common","url")
print(url)

在nacos里面写一个配置
[common]
url = www.qq.com
然后python就可以访问了

[root@localhost pythondemo]# python3 newdemo.py 
www.qq.com

标签: none

添加新评论