Skip to contentSkip to conversation

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

PATCH Applied Chen Hanxiao 2 participants 2 messages Nov 28, 2024 – Dec 13, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

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

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

---
 nfs4.0/lib/rpc/rpc.py | 4 ++--
 rpc/rpc.py            | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
nfs4.0/lib/rpc/rpc.py +2 -2
index 24a7fc7..243ef9e 100644
@@ -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")
rpc/rpc.py +2 -2
index 1fe285a..124e97a 100644
@@ -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
Signature · 1 line
2.43.5
Applied
#1 lore raw
Quoted 7 lines · Chen Hanxiao

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

Applied.

Thank you very much.

best wishes,
calum.

Quoted 35 lines
---
  nfs4.0/lib/rpc/rpc.py | 4 ++--
  rpc/rpc.py            | 4 ++--
  2 files changed, 4 insertions(+), 4 deletions(-)
nfs4.0/lib/rpc/rpc.py +2 -2
index 24a7fc7..243ef9e 100644
@@ -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")
rpc/rpc.py +2 -2
index 1fe285a..124e97a 100644
@@ -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