4

Sometimes my asyncio transports return None instead of IP address and port:

address, port = transport.get_extra_info('peername')

Here is what docs say:

'peername': the remote address to which the socket is connected, result of socket.socket.getpeername() (None on error)

However, nothing is said about the reasons causing the error. Should I try again? Should I close this connection immediately?

Max Malysh
  • 29,384
  • 19
  • 111
  • 115
  • You might need to do a little digging to find the reason for the error to know what to do. If you get the underlying `socket` (I think you should be able to get it from `get_extra_info('socket')` You can call `socket.getpeername()` directly, and see what error it returns. FWIW, I believe this is delegates to the Linux socket's `getpeername` function, which does [document possible error causes](http://man7.org/linux/man-pages/man2/getpeername.2.html) – dano May 23 '20 at 03:44

0 Answers0