mirror of
https://github.com/python-kasa/python-kasa.git
synced 2024-12-22 19:23:34 +00:00
avoid 'referenced before assignment' exception (#150)
This commit is contained in:
parent
29c91151e3
commit
8034c47b89
@ -42,6 +42,7 @@ class TPLinkSmartHomeProtocol:
|
||||
request = json.dumps(request)
|
||||
|
||||
timeout = TPLinkSmartHomeProtocol.DEFAULT_TIMEOUT
|
||||
sock = None
|
||||
try:
|
||||
sock = socket.create_connection((host, port), timeout)
|
||||
|
||||
@ -63,14 +64,17 @@ class TPLinkSmartHomeProtocol:
|
||||
|
||||
finally:
|
||||
try:
|
||||
sock.shutdown(socket.SHUT_RDWR)
|
||||
if sock:
|
||||
sock.shutdown(socket.SHUT_RDWR)
|
||||
except OSError:
|
||||
# OSX raises OSError when shutdown() gets called on a closed
|
||||
# socket. We ignore it here as the data has already been read
|
||||
# into the buffer at this point.
|
||||
pass
|
||||
|
||||
finally:
|
||||
sock.close()
|
||||
if sock:
|
||||
sock.close()
|
||||
|
||||
response = TPLinkSmartHomeProtocol.decrypt(buffer[4:])
|
||||
_LOGGER.debug("< (%i) %s", len(response), response)
|
||||
|
Loading…
Reference in New Issue
Block a user