/********************************************************************** * Python UDP broadcast PermissionError: [ Errno 13] Permission denied*Description:*use Python3 to do UDP broadcast, encountered this permission problem, then a burst of surprise, first look*to this problem of no permissions. * * 2016-12-10Shenzhen Nanshan Ping Shan village Zengjianfeng*********************************************************************/One, reference document: Python socket.error: [Errno13] Permission denied http:stackoverflow.com/questions/11457676/python-socket-error-errno-13-permission-denied two, error:1. Error symptom: [[email protected]~]#python main.pyFdsaf Traceback (most recent): File"main.py", line 11,inch<module>S.sendto ('ZENGJF'. Encode ('Utf-8'), address) Permissionerror: [Errno13] Permission denied [[email protected]~]#2. Error reason: Set the so_broadcast option,ifYou actually mean-to-send to a broadcast address:s.setsockopt (socket. Sol_socket, SOCKET. So_broadcast,1) 3. Test code:ImportSocket Address= ('255.255.255.255', 50000) s=Socket.socket (socket.af_inet, socket. SOCK_DGRAM) s.setsockopt (socket. Sol_socket, SOCKET. So_broadcast,1) whiletrue:msg=input ()if notmsg: BreakS.sendto ('ZENGJF'. Encode ('Utf-8'), address) s.close ()
Python UDP broadcast permissionerror: [Errno] Permission denied