improve error message on client when host/port is bad

for host name without port, None was used for the port
leading to a confusing error message

- do not call parse_host_port with None as defaultport argument
- improve error message when connection fails

+ fix an error in last line of parse_ipv6_host_and_port
+ fix some issues breaking PEP 8 rules

Change-Id: I437360be96449c164f0080e3c60f1685825d4780
Reviewed-on: https://forge.frm2.tum.de/review/c/secop/frappy/+/31911
Tested-by: Jenkins Automated Tests <pedersen+jenkins@frm2.tum.de>
Reviewed-by: Enrico Faulhaber <enrico.faulhaber@frm2.tum.de>
Reviewed-by: Markus Zolliker <markus.zolliker@psi.ch>
This commit is contained in:
2023-08-07 13:18:28 +02:00
parent 9df6794678
commit 2020928289
2 changed files with 18 additions and 12 deletions

View File

@@ -35,7 +35,7 @@ import time
import re
from frappy.errors import CommunicationFailedError, ConfigError
from frappy.lib import closeSocket, parse_host_port
from frappy.lib import closeSocket, parse_host_port, SECoP_DEFAULT_PORT
try:
from serial import Serial
@@ -176,11 +176,11 @@ class AsynTcp(AsynConn):
uri = uri[6:]
try:
host, port = parse_host_port(uri, self.default_settings.get('port'))
host, port = parse_host_port(uri, self.default_settings.get('port', SECoP_DEFAULT_PORT))
self.connection = socket.create_connection((host, port), timeout=self.timeout)
except (ConnectionRefusedError, socket.gaierror, socket.timeout) as e:
# indicate that retrying might make sense
raise CommunicationFailedError(str(e)) from None
raise CommunicationFailedError(f'can not connect to {host}:{port}, {e}') from None
def shutdown(self):
if self.connection: