This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: sock.proto does not reflect actual protocol
Type: behavior Stage: needs patch
Components: Extension Modules Versions: Python 3.11, Python 3.10, Python 3.9
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: christian.heimes, martin.panter
Priority: normal Keywords:

Created on 2016-08-20 16:21 by christian.heimes, last changed 2022-04-11 14:58 by admin.

Messages (3)
msg273222 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2016-08-20 16:21
The proto property of a socket object does not reflect the actual protocol of the socket file descriptor:

>>> import socket
>>> SO_PROTOCOL = getattr(socket, 'SO_PROTOCOL', 38)
>>> tcp = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>>> tcp.proto
0
>>> tcp.getsockopt(socket.SOL_SOCKET, SO_PROTOCOL)
6
>>> socket.getprotobyname('tcp')
6
msg273250 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2016-08-20 22:51
The documentation already says “Socket objects also have these (read-only) attributes that correspond to the values given to the socket constructor. . . . socket.proto”. For existing versions of Python, I’m not sure there is much else we can do.

In Issue 27377, I mentioned the idea of using the logic there (SO_PROTOCOL etc) to determine the socket.proto attribute automatically.
msg404587 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2021-10-21 11:59
I can still reproduce the issue with Python 3.9 and newer.

>>> import socket
>>> socket.socket(socket.AF_INET, socket.SOCK_STREAM).proto
0
History
Date User Action Args
2022-04-11 14:58:35adminsetgithub: 72003
2021-10-21 11:59:38christian.heimessettype: behavior
messages: + msg404587
versions: + Python 3.9, Python 3.10, Python 3.11, - Python 2.7, Python 3.5, Python 3.6
2016-08-20 22:51:34martin.pantersetnosy: + martin.panter

messages: + msg273250
versions: - Python 3.4
2016-08-20 16:21:59christian.heimescreate