python-consul
python-consul copied to clipboard
When creating a service registration, requests. exceptions. ConnectionError: HTTP ConnectionPool (host ='192.168.0.1', port = 8500): Max retries exceeded with URL
When creating a service registration, requests. exceptions. ConnectionError: HTTP ConnectionPool (host ='192.168.0.1', port = 8500): Max retries exceeded with URL
import consul from requests.exceptions import ConnectionError from retry import retry
def register_service_with_retry(service_name, service_address, service_port): @retry(ConnectionError, tries=3, delay=2, backoff=2) def _register_service(): c = consul.Consul() c.agent.service.register( service_name, address=service_address, port=service_port, )
try:
_register_service()
print("Service registered successfully.")
except ConnectionError as e:
print(f"Failed to register service: {e}")
Usage
register_service_with_retry("my-service", "192.168.0.1", 8500)