X-Git-Url: http://git.kaliko.me/?p=python-musicpd.git;a=blobdiff_plain;f=mpd.py;h=c924b3c758940ba4a1d4d43014339dc34e92cce7;hp=ae1f2b3c349a6360127ecd06f86451432d3f453d;hb=285bcce3de90f2e5474978d0bbb5fa4485b957f3;hpb=3bbc456dc51c95e8ad5bb4e270d781ed370bfe27 diff --git a/mpd.py b/mpd.py index ae1f2b3..c924b3c 100644 --- a/mpd.py +++ b/mpd.py @@ -275,6 +275,7 @@ class MPDClient(object): line = self._rfile.readline() if not line.endswith("\n"): raise ConnectionError, "Connection lost while reading MPD hello" + line = line.rstrip("\n") if not line.startswith(HELLO_PREFIX): raise ProtocolError, "Got invalid MPD hello: '%s'" % line self.mpd_version = line[len(HELLO_PREFIX):].strip() @@ -307,7 +308,11 @@ class MPDClient(object): raise socket.error, msg self._rfile = self._sock.makefile("rb") self._wfile = self._sock.makefile("wb") - self._hello() + try: + self._hello() + except (socket.error, MPDError): + self.disconnect() + raise def disconnect(self): self._rfile.close()