0

我正在设置一个 python 应用程序来监控 cups 服务器。我正在使用杯子包装纸pycups。python 应用程序与 cups 位于同一服务器中。创建打印作业并获取打印机信息和作业状态的调用工作正常,但是当我尝试拒绝/禁用打印机或取消作业时,我收到以下错误:cups.IPPError: (4096, 'Unauthorized')

我已经尝试在cupsd.conf文件中使用多个配置(当然还重新启动了 cups 服务),但似乎都没有工作(甚至尝试删除所有策略块)。

这是我的cupsd.conf(已删除<Policy authenticated>块)

LogLevel debug
ErrorPolicy retry-job
PageLogFormat
MaxLogSize 0
# Allow remote access
Port 631
Listen /var/run/cups/cups.sock
Browsing On
BrowseLocalProtocols none
DefaultAuthType Basic
WebInterface Yes
DefaultEncryption Never
<Location />
  Require user @SYSTEM
  Satisfy any
  # Allow remote administration...
  Order allow,deny
  Allow 127.0.0.1
  Allow localhost
</Location>
<Location /admin>
  AuthType Default
  Require user @SYSTEM
  # Allow remote administration...
  Order allow,deny
  Allow all
</Location>
<Location /admin/conf>
  AuthType Default
  Require user @SYSTEM
  # Allow remote access to the configuration files...
  Order allow,deny
  Allow all
</Location>
<Location /admin/log>
  AuthType Default
  Require user @SYSTEM
  Order allow,deny
  Allow all
  # Allow remote access to the log files...
  Order allow,deny
  Allow all
</Location>
<Policy default>
  JobPrivateAccess default
  JobPrivateValues default
  SubscriptionPrivateAccess default
  SubscriptionPrivateValues default
  <Limit Create-Job Print-Job Print-URI Validate-Job>
    AuthType None
    Satisfy any
    Order allow,deny
    Allow 127.0.0.1
  </Limit>
  <Limit Send-Document Send-URI Hold-Job Release-Job Restart-Job Purge-Jobs Set-Job-Attributes Create-Job-Subscription Renew-Subscription Cancel-Subscription Get-Notifications Reprocess-Job Cancel-Current-Job Suspend-Current-Job Resume-Job Cancel-My-Jobs Close-Job CUPS-Move-Job CUPS-Get-Document>
    Order allow,deny
    Require user @SYSTEM
    Satisfy any
    AuthType None
    Allow localhost
    Allow 127.0.0.1
  </Limit>
  <Limit CUPS-Add-Modify-Printer CUPS-Delete-Printer CUPS-Add-Modify-Class CUPS-Delete-Class CUPS-Set-Default CUPS-Get-Devices>
    AuthType None
    Order allow,deny
    Require user @SYSTEM
    Satisfy any
    Allow 127.0.0.1
  </Limit>
  <Limit Pause-Printer Resume-Printer Enable-Printer Disable-Printer Pause-Printer-After-Current-Job Hold-New-Jobs Release-Held-New-Jobs Deactivate-Printer Activate-Printer Restart-Printer Shutdown-Printer Startup-Printer Promote-Job Schedule-Job-After Cancel-Jobs CUPS-Accept-Jobs CUPS-Reject-Jobs>
    Order allow,deny
    Satisfy any
    Allow 127.0.0.1
    Allow localhost
  </Limit>
  <Limit CUPS-Authenticate-Job>
    Require user @OWNER @SYSTEM
    Order allow,deny
    Satisfy any
    AuthType None
    Allow 127.0.0.1
  </Limit>
  <Limit All>
    Order allow,deny
  </Limit>
</Policy>

每次我尝试禁用打印机或取消作业时,cups error_log 都会显示:

D [29/Oct/2019:18:52:47 +0000] [Client 21] Accepted from localhost:55986 (IPv6)
D [29/Oct/2019:18:52:47 +0000] [Client 21] Waiting for request.
D [29/Oct/2019:18:52:47 +0000] [Client 21] POST /admin/ HTTP/1.1
D [29/Oct/2019:18:52:47 +0000] cupsdSetBusyState: newbusy="Active clients", busy="Not busy"
D [29/Oct/2019:18:52:47 +0000] [Client 21] Read: status=200
D [29/Oct/2019:18:52:47 +0000] [Client 21] No authentication data provided.
D [29/Oct/2019:18:52:47 +0000] cupsdIsAuthorized: username=""
D [29/Oct/2019:18:52:47 +0000] [Client 21] cupsdSendHeader: code=401, type="text/html", auth_type=0
D [29/Oct/2019:18:52:47 +0000] [Client 21] WWW-Authenticate: , trc=\"y\"
D [29/Oct/2019:18:52:47 +0000] [Client 21] Closing connection.
D [29/Oct/2019:18:52:47 +0000] cupsdSetBusyState: newbusy="Not busy", busy="Active clients"

每次我尝试禁用打印机或取消作业时,cups access_log 都会记录:localhost - - [29/Oct/2019:17:15:16 +0000] "POST /admin/ HTTP/1.1" 401 0 - -

4

1 回答 1

0

解决了,我还必须配置 Location /admin 。

<Location /admin>
  AuthType Default
  Require user @SYSTEM
  Satisfy any
  Order allow,deny
  Allow localhost
</Location>
于 2019-10-30T16:04:53.483 回答