[New-bugs-announce] [issue37405] socket.getsockname() returns string instead of tuple

Brent Gardner report at bugs.python.org
Tue Jun 25 17:01:17 EDT 2019


New submission from Brent Gardner <bggardner at gmail.com>:

In Python 3.5.3, a socket with type AF_CAN returns a tuple in the form `(interface, )` from getsockname().  In Python 3.7.3, getsockname() returns a string (the name of the interface).  The documentation states "a tuple is used for the AF_CAN address family".  The string will break code that worked in 3.5.3 by raising errors such as "Value Error: too many values to unpack (expected 2)".

Example:

#3.5.3
import socket
s = socket.socket(socket.AF_CAN, socket.SOCK_RAW, socket.CAN_RAW)
s.bind(('vcan0',)) # requires tuple
s.getsockname() # returns tuple: ('vcan0', 29)

#3.7.3
import socket
s = socket.socket(socket.AF_CAN, socket.SOCK_RAW, socket.CAN_RAW)
s.bind(('vcan0',)) # requires tuple
s.getsockname() # returns string: 'vcan0'

----------
assignee: docs at python
components: Documentation
messages: 346559
nosy: Brent Gardner, docs at python
priority: normal
severity: normal
status: open
title: socket.getsockname() returns string instead of tuple
versions: Python 3.7

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue37405>
_______________________________________


More information about the New-bugs-announce mailing list