classification
Title: socket.create_connection needs to support full IPv6 argument
Type: behavior Stage: needs patch
Components: Library (Lib) Versions: Python 3.7, Python 3.6, Python 2.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Matthew Stoltenberg, gregory.p.smith, pitrou
Priority: normal Keywords:

Created on 2017-12-05 18:44 by Matthew Stoltenberg, last changed 2017-12-06 23:54 by pitrou.

Messages (4)
msg307674 - (view) Author: Matthew Stoltenberg (Matthew Stoltenberg) Date: 2017-12-05 18:44
The following causes a ValueError in the create_connection convenience function

import socket

sock1 = socket.create_connection(('::1', '80'))
sock2 = socket.create_connection(sock1.getpeername())
msg307771 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2017-12-06 22:17
Also note that a regular socket.connect() call supports the full form address:

>>> sock = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
>>> sock.connect(('::1', 12345, 0, 0))

Matthew, are you interested in submitting a Github PR for this issue?
msg307774 - (view) Author: Matthew Stoltenberg (Matthew Stoltenberg) Date: 2017-12-06 23:41
The naive change is to have the host, port tuple assignment use only the first two values from address. I can open a PR with that change (and update the docstring for the function) if that's the right change. For reference, the python socketpair implementation (if _socket is missing it) ignores flow_info and scope_id, but I'm not sure that's the right thing to do.
msg307776 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2017-12-06 23:54
I think we still want the full tuple passed to connect().  We may want
to truncate the tuple when used for other purposes.

Le 07/12/2017 à 00:41, Matthew Stoltenberg a écrit :
> 
> Matthew Stoltenberg <d3matt@gmail.com> added the comment:
> 
> The naive change is to have the host, port tuple assignment use only the first two values from address. I can open a PR with that change (and update the docstring for the function) if that's the right change. For reference, the python socketpair implementation (if _socket is missing it) ignores flow_info and scope_id, but I'm not sure that's the right thing to do.
> 
> ----------
> 
> _______________________________________
> Python tracker <report@bugs.python.org>
> <https://bugs.python.org/issue32224>
> _______________________________________
>
History
Date User Action Args
2017-12-06 23:54:27pitrousetmessages: + msg307776
2017-12-06 23:41:43Matthew Stoltenbergsetmessages: + msg307774
2017-12-06 22:17:42pitrousetversions: + Python 2.7, Python 3.7, - Python 3.4
nosy: + gregory.p.smith, pitrou

messages: + msg307771

stage: needs patch
2017-12-05 18:44:54Matthew Stoltenbergsettitle: socket.creaet_connection needs to support full IPv6 argument -> socket.create_connection needs to support full IPv6 argument
2017-12-05 18:44:36Matthew Stoltenbergcreate