Cannot use Token to obtain registered services through consul.agent.services ()
When I use the python-consul package and connect to the consul service with ACL added, I can register the service through the token, but I cannot get the registered service through the token Registration code: ` class RegisterService(object): def init(self, service_name, service_ip, service_port): self.service_name = service_name self.service_ip = service_ip self.service_port = service_port
def register_service(self):
connect_consul = ConnectConsul().connect_consul().connect_consul()
check = consul.Check.tcp(self.service_ip, self.service_port, "10s")
connect_consul.agent.service.register(self.service_name, "%s:%s:%s" % (self.service_name, self.service_ip,
self.service_port),
address=self.service_ip, port=self.service_port, check=check)
`
This can register the service normally
Get service code: ` class DiscoveryService(object): def init(self, service_name): self.service_name = service_name
def discovery_service(self):
connect_consul = ConnectConsul().connect_consul().connect_consul()
services = connect_consul.agent.services()
service = services.get(self.service_name)
if not service:
return None
address = "{0}:{1}".format(service['Address'], service['Port'])
return service, address
`
This return None
When I can get the service through http:
def discovery_service_request_mode(self): host = ConnectConsul().connect_consul().host port = ConnectConsul().connect_consul().port token = ConnectConsul().connect_consul().token url = "http://%s:%s/v1/agent/services" % (host, str(port)) payload = {} headers = { 'Authorization': 'Bearer %s' % token } response = requests.request("GET", url, headers=headers, data=payload) print(json.loads(response.text))
@doubledna 老哥来这儿 一起维护 https://github.com/poppyred/python-consul2