Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python 3.x socket.error: [Errno 10013] An attempt was made to access a socket in a way forbidden by its access permissions

I am getting this error trying to broadcast a UDP packet in Windows 7.

import socket
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.sendto("hello".encode("ascii"), ("<broadcast>", 5868))

If I change to 255.255.255.255, same deal. It works fine if I put a specific IP address (including 127.0.0.1). Same exact method (i.e., sending a packet to 255.255.255.255) works from .NET.

This is not affected by the Windows firewall (tried turning it off). I'm administrator and UAC is off and even with "run as administrator" it doesn't work. Somehow, I don't think it's an actual permissions problem.

like image 629
darda Avatar asked Oct 15 '25 07:10

darda


1 Answers

You seem to be missing an

s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)

after the socket creation. It enables the socket to broadcast.

Does it help?

like image 195
User Avatar answered Oct 17 '25 19:10

User