python-consul icon indicating copy to clipboard operation
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

Open chaojizhangdaxin opened this issue 6 years ago • 1 comments

When creating a service registration, requests. exceptions. ConnectionError: HTTP ConnectionPool (host ='192.168.0.1', port = 8500): Max retries exceeded with URL

chaojizhangdaxin avatar Feb 21 '19 07:02 chaojizhangdaxin

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)

ljluestc avatar Sep 05 '23 00:09 ljluestc