简体   繁体   English

Python3 Sockets - PermissionError: [Errno 1] Operation not allowed - 作为 root 运行

[英]Python3 Sockets - PermissionError: [Errno 1] Operation not permitted - running as root

I'm having a hard time with this small socket program I have.我很难使用我拥有的这个小型套接字程序。 The script runs fine one on Debian 11 server, but has the following error on an almost identical Debian 11 server.该脚本在 Debian 11 服务器上运行良好,但在几乎相同的 Debian 11 服务器上出现以下错误。

root@box:/home/user/python# sudo python3 script.py
Traceback (most recent call last):
  File "/home/user/python/script.py", line 18, in <module>
    UDPClientSocket.sendto(bytesToSend, serverAddress) # Send using created UDP socket
PermissionError: [Errno 1] Operation not permitted

The file is owned by root and executable.该文件由 root 拥有并且可执行。

-rwxr-xr-x 1 root root 942 May 27 16:24 script.py

Here is the script, its pretty basic.这是脚本,它非常基本。

import socket
from Cryptodome.Cipher import AES

serverAddress   = ("192.168.1.3", 3493)  #Packet Destination - IP/Port pair
sourceAddress   = ("192.168.3.2", 54921) #Source Socket - IP/Port pair
bufferSize      = 1024

data=b"garbage"          # message to send to server
key=b"xxxxxxxxxxxxxxxx"                           # key to encrypt data
salt=b'xxxxxxxxxxxxxxxx'                        # salt
obj=AES.new(key, AES.MODE_CBC, salt)            # set crypt settings
bytesToSend=obj.encrypt(data)                   # encrypt the data

UDPClientSocket = socket.socket(family=socket.AF_INET, type=socket.SOCK_DGRAM) # Create a UDP socket at client side
UDPClientSocket.bind((sourceAddress)) # Set local socket for source ip/port
UDPClientSocket.sendto(bytesToSend, serverAddress) # Send using created UDP socket

I am running as root, script is owned by root, what is wrong here?我以 root 身份运行,脚本归 root 所有,这里有什么问题?

Is there something I am doing in the script that is not allowed by the OS?我在脚本中做的事情是操作系统不允许的吗?

Updates:更新:

Uname for the box it does run on: Linux box 5.10.0-14-amd64 #1 SMP Debian 5.10.113-1 (2022-04-29) x86_64 GNU/Linux为它运行的机器命名: Linux box 5.10.0-14-amd64 #1 SMP Debian 5.10.113-1 (2022-04-29) x86_64 GNU/Linux

Uname for the box it does not run on: Linux box 5.10.0-13-amd64 #1 SMP Debian 5.10.106-1 (2022-03-17) x86_64 GNU/Linux未在其上运行的机器的名称: Linux box 5.10.0-13-amd64 #1 SMP Debian 5.10.106-1 (2022-03-17) x86_64 GNU/Linux

Python versions are the same, 3.9.2. Python 版本相同,都是 3.9.2。

Interface listing for the box I am attempting to run my script on:我尝试在其上运行脚本的框的界面列表:

# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
2: net1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 04:d9:f5:xx:xx:xx brd ff:ff:ff:ff:ff:ff
    altname enp2s0
    inet 192.168.3.2/28 brd 192.168.3.15 scope global net1
       valid_lft forever preferred_lft forever

I figured it out, mistake on my part.我想通了,我的错误。

Turns out it was the firewall.原来是防火墙。 I have iptables with output filters, and forgot the iptables-save before the last reboot, so the output rule allowing the UDP sendto was denied.我有带有输出过滤器的 iptables,并且在上次重新启动之前忘记了 iptables-save,因此允许 UDP sendto 的输出规则被拒绝。

Figured it out when I attempted ncat in udp mode and it failed with WRITE ERROR当我在 udp 模式下尝试 ncat 时发现它并因WRITE ERROR失败

I appreciate everyone's input though.我感谢大家的意见。

Run this to update运行此更新


pip install --upgrade setuptools pip

try again再试一次

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 覆盖范围 - PermissionError: [Errno 1] 不允许操作 - Coverage - PermissionError: [Errno 1] Operation not permitted PermissionError:[Errno 1]写后读取时,Python中不允许进行此操作 - PermissionError: [Errno 1] Operation not permitted in Python while reading after write Dockerfile Raspberry PI Python pip install "PermissionError: [Errno 1] Operation not allowed" - Dockerfile Raspberry PI Python pip install "PermissionError: [Errno 1] Operation not permitted" 使用Stanfordcorenlp发生PermissionError:[Errno 1]不允许操作 - using Stanfordcorenlp occurs PermissionError: [Errno 1] Operation not permitted PermissionError: [Errno 1] 在 iPadOS 14 上使用 Pyto 时不允许操作 - PermissionError: [Errno 1] Operation not permitted while using Pyto on iPadOS 14 PermissionError:[Errno 1] macOS Catalina 更新后不允许操作 - PermissionError: [Errno 1] Operation not permitted after macOS Catalina Update PermissionError: [Errno 1] docker conatiner 尝试连接到数据库时不允许操作 - PermissionError: [Errno 1] Operation not permitted while a docker conatiner tries to connect to database Python 中的 Chmod - [Errno 1] 不允许操作 - Chmod in Python - [Errno 1] Operation not permitted Python fcntl.ioctl [Errno 1] 不允许操作 - Python fcntl.ioctl [Errno 1] Operation not permitted PermissionError:[Errno 1] 不允许操作:'/Users/<local_path> /venv/pyvenv.cfg'</local_path> - PermissionError: [Errno 1] Operation not permitted: '/Users/<local_path>/venv/pyvenv.cfg'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM