Skip to content

Commit 5acd134

Browse files
authored
Merge pull request #585 from x011/fix-winerror-10022
Fix WinError 10022: Handle invalid socket arguments in send_discovery_request
2 parents 3f56596 + 56f41fa commit 5acd134

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

tinytuya/scanner.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,11 @@ def send_discovery_request( iface_list=None ):
234234

235235
log.debug( 'Sending discovery broadcast from %r to %r on port %r', address, iface['broadcast'], iface['port'] )
236236
# the official app always sends it twice, so do the same
237-
iface['socket'].sendto( iface['payload'], (iface['broadcast'], iface['port']) )
238-
iface['socket'].sendto( iface['payload'], (iface['broadcast'], iface['port']) )
237+
try:
238+
iface['socket'].sendto( iface['payload'], (iface['broadcast'], iface['port']) )
239+
iface['socket'].sendto( iface['payload'], (iface['broadcast'], iface['port']) )
240+
except socket.error as e:
241+
log.error(f"Failed to send discovery broadcast to {iface['broadcast']}:{iface['port']}: {e}")
239242

240243
if close_sockets:
241244
iface['socket'].close()

0 commit comments

Comments
 (0)