mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-01-24 13:47:05 +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)
|
request = json.dumps(request)
|
||||||
|
|
||||||
timeout = TPLinkSmartHomeProtocol.DEFAULT_TIMEOUT
|
timeout = TPLinkSmartHomeProtocol.DEFAULT_TIMEOUT
|
||||||
|
sock = None
|
||||||
try:
|
try:
|
||||||
sock = socket.create_connection((host, port), timeout)
|
sock = socket.create_connection((host, port), timeout)
|
||||||
|
|
||||||
@ -63,13 +64,16 @@ class TPLinkSmartHomeProtocol:
|
|||||||
|
|
||||||
finally:
|
finally:
|
||||||
try:
|
try:
|
||||||
|
if sock:
|
||||||
sock.shutdown(socket.SHUT_RDWR)
|
sock.shutdown(socket.SHUT_RDWR)
|
||||||
except OSError:
|
except OSError:
|
||||||
# OSX raises OSError when shutdown() gets called on a closed
|
# OSX raises OSError when shutdown() gets called on a closed
|
||||||
# socket. We ignore it here as the data has already been read
|
# socket. We ignore it here as the data has already been read
|
||||||
# into the buffer at this point.
|
# into the buffer at this point.
|
||||||
pass
|
pass
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
|
if sock:
|
||||||
sock.close()
|
sock.close()
|
||||||
|
|
||||||
response = TPLinkSmartHomeProtocol.decrypt(buffer[4:])
|
response = TPLinkSmartHomeProtocol.decrypt(buffer[4:])
|
||||||
|
Loading…
Reference in New Issue
Block a user