Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove old aliases to OSError #1473

Merged
merged 1 commit into from
Apr 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pymodbus/client/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ def _get_address_family(cls, address):
"""Get the correct address family."""
try:
_ = socket.inet_pton(socket.AF_INET6, address)
except socket.error: # not a valid ipv6 address
except OSError: # not a valid ipv6 address
return socket.AF_INET
return socket.AF_INET6

Expand Down
2 changes: 1 addition & 1 deletion pymodbus/client/sync_diag.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def connect(self):
timeout=self.params.timeout,
source_address=self.params.source_address,
)
except socket.error as msg:
except OSError as msg:
Log.error(LOG_MSGS["connfail_msg"], self.params.host, self.params.port, msg)
self.close()
return self.socket is not None
Expand Down
2 changes: 1 addition & 1 deletion pymodbus/client/tcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def connect(self):
"Connection to Modbus server established. Socket {}",
self.socket.getsockname(),
)
except socket.error as msg:
except OSError as msg:
Log.error(
"Connection to ({}, {}) failed: {}",
self.params.host,
Expand Down
2 changes: 1 addition & 1 deletion pymodbus/client/tls.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def connect(self):
)
self.socket.settimeout(self.params.timeout)
self.socket.connect((self.params.host, self.params.port))
except socket.error as msg:
except OSError as msg:
Log.error(
"Connection to ({}, {}) failed: {}",
self.params.host,
Expand Down
2 changes: 1 addition & 1 deletion pymodbus/client/udp.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def connect(self):
family = ModbusUdpClient._get_address_family(self.params.host)
self.socket = socket.socket(family, socket.SOCK_DGRAM)
self.socket.settimeout(self.params.timeout)
except socket.error as exc:
except OSError as exc:
Log.error("Unable to create udp socket {}", exc)
self.close()
return self.socket is not None
Expand Down
7 changes: 1 addition & 6 deletions pymodbus/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
]

# pylint: disable=missing-type-doc
import socket
import struct
import time
from functools import partial
Expand Down Expand Up @@ -317,11 +316,7 @@ def _transact(self, packet, response_length, full=False, broadcast=False):
result = self._recv(response_length, full)
# result2 = self._recv(response_length, full)
Log.debug("RECV: {}", result, ":hex")
except (
socket.error,
ModbusIOException,
InvalidMessageReceivedException,
) as msg:
except (OSError, ModbusIOException, InvalidMessageReceivedException) as msg:
if self.reset_socket:
self.client.close()
Log.debug("Transaction failed. ({}) ", msg)
Expand Down
6 changes: 3 additions & 3 deletions test/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ def settimeout(self, *a, **kwa):
assert client.connect()

with mock.patch.object(socket, "socket") as mock_method:
mock_method.side_effect = socket.error()
mock_method.side_effect = OSError()
client = lib_client.ModbusUdpClient("127.0.0.1")
assert not client.connect()

Expand All @@ -504,7 +504,7 @@ def test_client_tcp_connect():
assert client.connect()

with mock.patch.object(socket, "create_connection") as mock_method:
mock_method.side_effect = socket.error()
mock_method.side_effect = OSError()
client = lib_client.ModbusTcpClient("127.0.0.1")
assert not client.connect()

Expand All @@ -516,7 +516,7 @@ def test_client_tls_connect():
assert client.connect()

with mock.patch.object(socket, "create_connection") as mock_method:
mock_method.side_effect = socket.error()
mock_method.side_effect = OSError()
client = lib_client.ModbusTlsClient("127.0.0.1")
assert not client.connect()

Expand Down
2 changes: 1 addition & 1 deletion test/test_client_sync_diag.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def test_tcp_diag_client_connect(self):
assert client.connect()

with mock.patch.object(socket, "create_connection") as mock_method:
mock_method.side_effect = socket.error()
mock_method.side_effect = OSError()
client = ModbusTcpDiagClient()
assert not client.connect()

Expand Down