又是我来自Running Python server forever .我确实将我的文件上传到服务器,但我得到了这个:
Traceback (most recent call last):
File "./application", line 42, in <module>
s.bind((TCP_IP, TCP_PORT))
File "<string>", line 1, in bind
socket.error: [Errno 13] Permission denied
供您引用,代码在这里:
...
TCP_IP = ''
TCP_PORT = 9090
BUFFER_SIZE = 256
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((TCP_IP, TCP_PORT))
s.listen(1)
while True:
conn, addr = s.accept()
ClientThread(conn, addr).start()
当套接字绑定(bind)到端口 9090(或与此相关的任何其他端口)时,它只返回此异常。我不需要成为 root
,因为 port > 1024
。
我应该改变什么?是TCP_IP还是TCP_PORT的问题?
~机会
最佳答案
尝试使用 '0.0.0.0
' 作为绑定(bind)地址。在 Linux 中,这意味着所有接口(interface)。
TCP_IP = '0.0.0.0'
并确保 SELinux 被禁用。
关于python - 绑定(bind)套接字时权限被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12443792/