gpt4 book ai didi

linux - Python 套接字错误 : [Errno 13] Permission denied

转载 作者:IT王子 更新时间:2023-10-29 00:22:35 26 4
gpt4 key购买 nike

使用 Linux 和 Python,我想通过广播发送一些数据:

d = b'109u433279423423423'    

import socket

s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

s.sendto(d, 0, ('192.168.0.255', 9))

我在 root 下启动这个脚本并得到这个错误:

s.sendto(d, 0, ('192.168.0.255', 9)) socket.error: [Errno 13]
Permission denied

怎么了?

最佳答案

您正在尝试发送到一个广播地址。这是不允许的,请参阅 sendto(2) 的联机帮助页:

EACCES (For UDP sockets) An attempt was made to send to a network/broadcast address as though it was a unicast address.

设置 SO_BROADCAST 选项,如果你真的想发送到一个广播地址:

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

关于linux - Python 套接字错误 : [Errno 13] Permission denied,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11457676/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com