Skip to content

Commit

Permalink
Close socket properly
Browse files Browse the repository at this point in the history
  • Loading branch information
vrachieru committed Jun 3, 2019
1 parent c626999 commit 22eac6a
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion tplink_smartplug/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,14 @@ def command(self, cmd):
if isinstance(cmd, dict):
cmd = json.dumps(cmd)

sock = None
try:
sock = socket.create_connection((self.host, self.port), self.timeout)
sock.send(self.encrypt(cmd))
data = sock.recv(4096)
finally:
sock.close()
if sock:
sock.close()

response = self.decrypt(data[4:])
response = json.loads(response)
Expand Down

0 comments on commit 22eac6a

Please sign in to comment.