You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
23 KiB
23 KiB
<html>
<head>
</head>
</html>
Retrieve list of active proxy endpoints¶
In [1]:
import json
import re
import requests
my_headers = {
"Content-Type": "application/json",
"Accept": "application/json",
}
response = requests.get(
"http://traefik:8080/api/http/routers",
headers=my_headers,
)
initial = response.json()
for x in initial:
service = x["rule"]
find = re.findall("Host\(`([^\)]+)`\)", service)
try:
print(find[0])
except:
pass
--------------------------------------------------------------------------- gaierror Traceback (most recent call last) File ~/Library/Python/3.8/lib/python/site-packages/urllib3/connection.py:174, in HTTPConnection._new_conn(self) 173 try: --> 174 conn = connection.create_connection( 175 (self._dns_host, self.port), self.timeout, **extra_kw 176 ) 178 except SocketTimeout: File ~/Library/Python/3.8/lib/python/site-packages/urllib3/util/connection.py:72, in create_connection(address, timeout, source_address, socket_options) 68 return six.raise_from( 69 LocationParseError(u"'%s', label empty or too long" % host), None 70 ) ---> 72 for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 73 af, socktype, proto, canonname, sa = res File /Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/socket.py:918, in getaddrinfo(host, port, family, type, proto, flags) 917 addrlist = [] --> 918 for res in _socket.getaddrinfo(host, port, family, type, proto, flags): 919 af, socktype, proto, canonname, sa = res gaierror: [Errno 8] nodename nor servname provided, or not known During handling of the above exception, another exception occurred: NewConnectionError Traceback (most recent call last) File ~/Library/Python/3.8/lib/python/site-packages/urllib3/connectionpool.py:703, in HTTPConnectionPool.urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw) 702 # Make the request on the httplib connection object. --> 703 httplib_response = self._make_request( 704 conn, 705 method, 706 url, 707 timeout=timeout_obj, 708 body=body, 709 headers=headers, 710 chunked=chunked, 711 ) 713 # If we're going to release the connection in ``finally:``, then 714 # the response doesn't need to know about the connection. Otherwise 715 # it will also try to release it and we'll have a double-release 716 # mess. File ~/Library/Python/3.8/lib/python/site-packages/urllib3/connectionpool.py:398, in HTTPConnectionPool._make_request(self, conn, method, url, timeout, chunked, **httplib_request_kw) 397 else: --> 398 conn.request(method, url, **httplib_request_kw) 400 # We are swallowing BrokenPipeError (errno.EPIPE) since the server is 401 # legitimately able to close the connection after sending a valid response. 402 # With this behaviour, the received response is still readable. File ~/Library/Python/3.8/lib/python/site-packages/urllib3/connection.py:239, in HTTPConnection.request(self, method, url, body, headers) 238 headers["User-Agent"] = _get_default_user_agent() --> 239 super(HTTPConnection, self).request(method, url, body=body, headers=headers) File /Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/http/client.py:1252, in HTTPConnection.request(self, method, url, body, headers, encode_chunked) 1251 """Send a complete request to the server.""" -> 1252 self._send_request(method, url, body, headers, encode_chunked) File /Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/http/client.py:1298, in HTTPConnection._send_request(self, method, url, body, headers, encode_chunked) 1297 body = _encode(body, 'body') -> 1298 self.endheaders(body, encode_chunked=encode_chunked) File /Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/http/client.py:1247, in HTTPConnection.endheaders(self, message_body, encode_chunked) 1246 raise CannotSendHeader() -> 1247 self._send_output(message_body, encode_chunked=encode_chunked) File /Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/http/client.py:1007, in HTTPConnection._send_output(self, message_body, encode_chunked) 1006 del self._buffer[:] -> 1007 self.send(msg) 1009 if message_body is not None: 1010 1011 # create a consistent interface to message_body File /Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/http/client.py:947, in HTTPConnection.send(self, data) 946 if self.auto_open: --> 947 self.connect() 948 else: File ~/Library/Python/3.8/lib/python/site-packages/urllib3/connection.py:205, in HTTPConnection.connect(self) 204 def connect(self): --> 205 conn = self._new_conn() 206 self._prepare_conn(conn) File ~/Library/Python/3.8/lib/python/site-packages/urllib3/connection.py:186, in HTTPConnection._new_conn(self) 185 except SocketError as e: --> 186 raise NewConnectionError( 187 self, "Failed to establish a new connection: %s" % e 188 ) 190 return conn NewConnectionError: <urllib3.connection.HTTPConnection object at 0x117eb6760>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known During handling of the above exception, another exception occurred: MaxRetryError Traceback (most recent call last) File ~/Library/Python/3.8/lib/python/site-packages/requests/adapters.py:489, in HTTPAdapter.send(self, request, stream, timeout, verify, cert, proxies) 488 if not chunked: --> 489 resp = conn.urlopen( 490 method=request.method, 491 url=url, 492 body=request.body, 493 headers=request.headers, 494 redirect=False, 495 assert_same_host=False, 496 preload_content=False, 497 decode_content=False, 498 retries=self.max_retries, 499 timeout=timeout, 500 ) 502 # Send the request. 503 else: File ~/Library/Python/3.8/lib/python/site-packages/urllib3/connectionpool.py:787, in HTTPConnectionPool.urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw) 785 e = ProtocolError("Connection aborted.", e) --> 787 retries = retries.increment( 788 method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2] 789 ) 790 retries.sleep() File ~/Library/Python/3.8/lib/python/site-packages/urllib3/util/retry.py:592, in Retry.increment(self, method, url, response, error, _pool, _stacktrace) 591 if new_retry.is_exhausted(): --> 592 raise MaxRetryError(_pool, url, error or ResponseError(cause)) 594 log.debug("Incremented Retry for (url='%s'): %r", url, new_retry) MaxRetryError: HTTPConnectionPool(host='traefik', port=8080): Max retries exceeded with url: /api/http/routers (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x117eb6760>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known')) During handling of the above exception, another exception occurred: ConnectionError Traceback (most recent call last) /Users/donaldrich/Projects/secrets/code/unpublished/directus/Add traefic routers.ipynb Cell 2 in <cell line: 10>() <a href='vscode-notebook-cell:/Users/donaldrich/Projects/secrets/code/unpublished/directus/Add%20traefic%20routers.ipynb#ch0000002?line=2'>3</a> import requests <a href='vscode-notebook-cell:/Users/donaldrich/Projects/secrets/code/unpublished/directus/Add%20traefic%20routers.ipynb#ch0000002?line=4'>5</a> my_headers = { <a href='vscode-notebook-cell:/Users/donaldrich/Projects/secrets/code/unpublished/directus/Add%20traefic%20routers.ipynb#ch0000002?line=5'>6</a> "Content-Type": "application/json", <a href='vscode-notebook-cell:/Users/donaldrich/Projects/secrets/code/unpublished/directus/Add%20traefic%20routers.ipynb#ch0000002?line=6'>7</a> "Accept": "application/json", <a href='vscode-notebook-cell:/Users/donaldrich/Projects/secrets/code/unpublished/directus/Add%20traefic%20routers.ipynb#ch0000002?line=7'>8</a> } ---> <a href='vscode-notebook-cell:/Users/donaldrich/Projects/secrets/code/unpublished/directus/Add%20traefic%20routers.ipynb#ch0000002?line=9'>10</a> response = requests.get( <a href='vscode-notebook-cell:/Users/donaldrich/Projects/secrets/code/unpublished/directus/Add%20traefic%20routers.ipynb#ch0000002?line=10'>11</a> "http://traefik:8080/api/http/routers", <a href='vscode-notebook-cell:/Users/donaldrich/Projects/secrets/code/unpublished/directus/Add%20traefic%20routers.ipynb#ch0000002?line=11'>12</a> headers=my_headers, <a href='vscode-notebook-cell:/Users/donaldrich/Projects/secrets/code/unpublished/directus/Add%20traefic%20routers.ipynb#ch0000002?line=12'>13</a> ) <a href='vscode-notebook-cell:/Users/donaldrich/Projects/secrets/code/unpublished/directus/Add%20traefic%20routers.ipynb#ch0000002?line=15'>16</a> initial = response.json() <a href='vscode-notebook-cell:/Users/donaldrich/Projects/secrets/code/unpublished/directus/Add%20traefic%20routers.ipynb#ch0000002?line=18'>19</a> for x in initial: File ~/Library/Python/3.8/lib/python/site-packages/requests/api.py:73, in get(url, params, **kwargs) 62 def get(url, params=None, **kwargs): 63 r"""Sends a GET request. 64 65 :param url: URL for the new :class:`Request` object. (...) 70 :rtype: requests.Response 71 """ ---> 73 return request("get", url, params=params, **kwargs) File ~/Library/Python/3.8/lib/python/site-packages/requests/api.py:59, in request(method, url, **kwargs) 55 # By using the 'with' statement we are sure the session is closed, thus we 56 # avoid leaving sockets open which can trigger a ResourceWarning in some 57 # cases, and look like a memory leak in others. 58 with sessions.Session() as session: ---> 59 return session.request(method=method, url=url, **kwargs) File ~/Library/Python/3.8/lib/python/site-packages/requests/sessions.py:587, in Session.request(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json) 582 send_kwargs = { 583 "timeout": timeout, 584 "allow_redirects": allow_redirects, 585 } 586 send_kwargs.update(settings) --> 587 resp = self.send(prep, **send_kwargs) 589 return resp File ~/Library/Python/3.8/lib/python/site-packages/requests/sessions.py:701, in Session.send(self, request, **kwargs) 698 start = preferred_clock() 700 # Send the request --> 701 r = adapter.send(request, **kwargs) 703 # Total elapsed time of the request (approximately) 704 elapsed = preferred_clock() - start File ~/Library/Python/3.8/lib/python/site-packages/requests/adapters.py:565, in HTTPAdapter.send(self, request, stream, timeout, verify, cert, proxies) 561 if isinstance(e.reason, _SSLError): 562 # This branch is for urllib3 v1.22 and later. 563 raise SSLError(e, request=request) --> 565 raise ConnectionError(e, request=request) 567 except ClosedPoolError as e: 568 raise ConnectionError(e, request=request) ConnectionError: HTTPConnectionPool(host='traefik', port=8080): Max retries exceeded with url: /api/http/routers (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x117eb6760>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known'))