def _gen_addresses_where_possible(hostname):
"""Yield IPv4 and IPv6 addresses for `hostname`.
A variant of `_gen_addresses` that ignores some resolution failures. The
addresses returned are only those that are resolvable at the time this
function is called. Specifically the following errors are ignored:
+----------------+-----------------------------------------------+
| EAI_ADDRFAMILY | The specified network host does not have any |
| | network addresses in the requested address |
| | family. |
+----------------+-----------------------------------------------+
| EAI_AGAIN | The name server returned a temporary failure |
| | indication. Try again later. |
+----------------+-----------------------------------------------+
| EAI_FAIL | The name server returned a permanent failure |
| | indication. |
+----------------+-----------------------------------------------+
| EAI_NODATA | The specified network host exists, but does |
| | not have any network addresses defined. |
+----------------+-----------------------------------------------+
| EAI_NONAME | The node or service is not known; or both node|
| | and service are NULL; or AI_NUMERICSERV was |
| | specified and service was not a numeric |
| | port-number string. |
+----------------+-----------------------------------------------+
Descriptions from getaddrinfo(3).
"""
try:
yield from _gen_addresses(hostname)
except socket.gaierror as error:
if error.errno in _gen_addresses_where_possible_suppress:
# Log this but otherwise suppress/ignore for now.
logger.warning("Could not resolve %s: %s", hostname, error)
else:
raise
评论列表
文章目录