diff --git a/bebop/browser.py b/bebop/browser.py index 1e3494d..be81fd0 100644 --- a/bebop/browser.py +++ b/bebop/browser.py @@ -222,7 +222,11 @@ class Browser: else: pass # TODO - response = Response.parse(req.proceed()) + data = req.proceed() + if not data: + self.set_status_error(f"Server did not respond in time ({url}).") + return + response = Response.parse(data) if not response: self.set_status_error(f"Server response parsing failed ({url}).") return diff --git a/bebop/protocol.py b/bebop/protocol.py index 33356ec..fe42f01 100644 --- a/bebop/protocol.py +++ b/bebop/protocol.py @@ -81,7 +81,7 @@ class Request: self.payload += LINE_TERM try: - sock = socket.create_connection((hostname, port)) + sock = socket.create_connection((hostname, port), timeout=10) except OSError as exc: self.state = Request.STATE_CONNECTION_FAILED self.error = exc.strerror @@ -124,7 +124,10 @@ class Request: self.ssock.sendall(self.payload) response = b"" while True: - buf = self.ssock.recv(4096) + try: + buf = self.ssock.recv(4096) + except socket.timeout: + buf = None if not buf: return response response += buf