J'ai du code lamda:
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.bind(("", 53))
host, port = sock.getsockname()
except socket.error:
raise exception.ProxyBindError("Could not bind port {}:{}".format(host, port))
sys.exit(1)
Alors que ce code devrait me retourner
Could not bind port 0.0.0.0:53
il me crache ceci:
Traceback (most recent call last):
File "core.py", line 59, in <module>
raise exception.ProxyBindError("Could not bind port {}:{}".format(host, port))
NameError: name 'host' is not defined
Si je définis mon code ceci:
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.bind(("", 53))
except socket.error:
raise exception.ProxyBindError("Could not bind port {}:{}".format(sock.getsockname()[0], sock.getsockname()[1]))
sys.exit(1)
le résultat n'est pas plus concluant:
Traceback (most recent call last):
File "core.py", line 58, in <module>
raise exception.ProxyBindError("Could not bind port {}:{}".format(sock.getsockname()[0], sock.getsockname()[1]))
exception.ProxyBindError: 'Could not bind port 0.0.0.0:0'
Du coup deux questions:
- pourquoi le tuple unpacking ne fonctionne pas?
- dans le second exemple sock.getsockname()[1] me retourne 0 alors que cela devrait clairement retourner 53.
P.S: Il est 3h du mat' donc je suis certain que j'ai juste de la me*** dans les yeux.