Python3 中 "except socket.error as (code, msg)" 的等价物是什么?

What is an equivalent of "except socket.error as (code, msg)" in Python3?

我在 Python2 中有这个 try/except 块,但由于行 except socket.error as (code, msg):

而在 Python3 中没有 运行
try:
    (conn, (ip,port)) = tcpServer.accept()
except socket.error as (code, msg):
    if code != errno.EINTR:
        raise
    else:
        break

Python3 中的等价物是什么?有没有一种方法适用于两个 Python 版本?

根据删除旧异常的 PEP,PEP 3151,这种方式应该可行:

try:
    (conn, (ip,port)) = tcpServer.accept()
except socket.error as e:
    if e.errno != errno.EINTR:
        raise
    else:
        break

请注意,在 Python > 3.3 中,socket.errorOSErrordeprecated alias