diff mbox series

pynfs: rpc.py: use OSError.errno to fix a not subscriptable exception

Message ID 20241128123642.1636-1-chenhx.fnst@fujitsu.com (mailing list archive)
State New
Headers show
Series pynfs: rpc.py: use OSError.errno to fix a not subscriptable exception | expand

Commit Message

Chen Hanxiao Nov. 28, 2024, 12:36 p.m. UTC
In python3, socket.error is a deprecated alias of OSError
https://docs.python.org/3/library/socket.html#socket.error

Also, use socket.error[0] will raise:
TypeError: 'OSError' object is not subscriptable

Signed-off-by: Chen Hanxiao <chenhx.fnst@fujitsu.com>
---
 nfs4.0/lib/rpc/rpc.py | 4 ++--
 rpc/rpc.py            | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/nfs4.0/lib/rpc/rpc.py b/nfs4.0/lib/rpc/rpc.py
index 24a7fc7..243ef9e 100644
--- a/nfs4.0/lib/rpc/rpc.py
+++ b/nfs4.0/lib/rpc/rpc.py
@@ -226,8 +226,8 @@  class RPCClient(object):
             try:
                 sock.bind(('', port))
                 return
-            except socket.error as why:
-                if why[0] == errno.EADDRINUSE:
+            except OSError as why:
+                if why.errno == errno.EADDRINUSE:
                     port += 1
                 else:
                     print("Could not use low port")
diff --git a/rpc/rpc.py b/rpc/rpc.py
index 1fe285a..124e97a 100644
--- a/rpc/rpc.py
+++ b/rpc/rpc.py
@@ -845,8 +845,8 @@  class ConnectionHandler(object):
             try:
                 s.bind(('', using))
                 return
-            except socket.error as why:
-                if why[0] == errno.EADDRINUSE:
+            except OSError as why:
+                if why.errno == errno.EADDRINUSE:
                     using += 1
                     if port < 1024 <= using:
                         # If we ask for a secure port, make sure we don't