Python 找不到记录器的处理程序";“洪水”;
我有一个用于cronjob的python脚本,它可以删除超过3天的torrent。如果我从终端运行该脚本,它就会工作,但是crontab给了我这个错误Python 找不到记录器的处理程序";“洪水”;,python,logging,crontab,Python,Logging,Crontab,我有一个用于cronjob的python脚本,它可以删除超过3天的torrent。如果我从终端运行该脚本,它就会工作,但是crontab给了我这个错误无法找到记录器“flouge”的处理程序。谁能告诉我如何解决这个问题吗 这是python脚本: #!/usr/bin/python from deluge.log import LOG as log from deluge.ui.client import client import deluge.componen
无法找到记录器“flouge”的处理程序。谁能告诉我如何解决这个问题吗
这是python脚本:
#!/usr/bin/python
from deluge.log import LOG as log
from deluge.ui.client import client
import deluge.component as component
from twisted.internet import reactor, defer
import time
############
cliconnect = client.connect(host='127.0.0.1',port=58846)
seeddir = "/home/mou/CPDownloads" # Directory to ignore for torrents to remain seeding
timedifference = 3 # Remove torrents older than this this time (in days)
is_interactive = False # Set this to True to allow direct output or set to False for cron
do_remove_data = True # Set to True to delete torrent data as well, false to leave it
###############
oldcount = 0
skipcount = 0
seedcount = 0
errorcount = 0
torrent_ids = []
def printSuccess(dresult, is_success, smsg):
global is_interactive
if is_interactive:
if is_success:
print "[+]", smsg
else:
print "[i]", smsg
def printError(emsg):
global is_interactive
if is_interactive:
print "[e]", emsg
def endSession(esresult):
if esresult:
print esresult
reactor.stop()
else:
client.disconnect()
printSuccess(None, False, "Client disconnected.")
reactor.stop()
def printReport(rresult):
if errorcount > 0:
printError(None, "Failed! Number of errors: %i" % (errorcount))
else:
if oldcount > 0:
printSuccess(None, True, "Removed %i torrents -- Skipped %i torrents -- Seeding %i torrents" % (oldcount, skipcount, seedcount))
else:
printSuccess(None, True, "No old torrents! -- Skipped %i torrents -- Seeding %i torrents" % (skipcount, seedcount))
endSession(None)
def on_torrents_status(torrents):
global filtertime
tlist=[]
for torrent_id, status in torrents.items():
if status["save_path"] == seeddir:
global seedcount
seedcount += 1
else:
unixtime = "%s" % (status["time_added"])
numunixtime = int(unixtime[:-2])
humantime = time.ctime(numunixtime)
if numunixtime < filtertime:
global do_remove_data
global oldcount
oldcount += 1
successmsg = " Removed %s: %s from %s" % (humantime, status["name"], status["save_path"])
errormsg = "Error removing %s" % (status["name"])
tlist.append(client.core.remove_torrent(torrent_id, do_remove_data).addCallbacks(printSuccess, printError, callbackArgs = (True, successmsg), errbackArgs = (errormsg)))
else:
global skipcount
skipcount += 1
printSuccess(None, False, " Skipping %s: %s from %s" % (humantime, status["name"], status["save_path"]))
defer.DeferredList(tlist).addCallback(printReport)
def on_session_state(result):
client.core.get_torrents_status({"id": result}, ["name","time_added","save_path",]).addCallback(on_torrents_status)
def on_connect_success(result):
printSuccess(None, True, "Connection was successful!")
global timedifference
global filtertime
curtime = time.time()
filtertime = curtime - (timedifference * 24 * 60 * 60)
printSuccess(None, False, "Current unix time is %i" % (curtime))
printSuccess(None, False, "Filtering torrents older than %s" % (time.ctime(int(filtertime))))
client.core.get_session_state().addCallback(on_session_state)
cliconnect.addCallbacks(on_connect_success, endSession, errbackArgs=("Connection failed: check settings and try again."))
reactor.run()
这是crontab作业的日志:
找不到记录器“洪水”的处理程序
找不到记录器“洪水”的处理程序
找不到记录器“洪水”的处理程序
找不到记录器“洪水”的处理程序
找不到记录器“洪水”的处理程序
找不到记录器“洪水”的处理程序
找不到记录器“洪水”的处理程序
找不到记录器“洪水”的处理程序
找不到记录器“洪水”的处理程序
找不到记录器“洪水”的处理程序
找不到记录器“洪水”的处理程序
找不到记录器“洪水”的处理程序
添加调试代码后,出现以下错误:
DEBUG:deluge:ConfigManager started..
INFO:deluge:Connecting to daemon at 127.0.0.1:58846..
INFO:deluge:Connected to daemon at 127.0.0.1:58846..
ERROR:deluge:RPCError Message Received!
--------------------------------------------------------------------------------
RPCRequest: daemon.login(localclient, f4f86361c7b9443464d0078f8d7c012e2ed63ce9)
--------------------------------------------------------------------------------
File "/usr/lib/python2.7/dist-packages/deluge/core/rpcserver.py", line 259, in dispatch
ret = component.get("AuthManager").authorize(*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/deluge/core/authmanager.py", line 93, in authorize
raise BadLoginError("Password does not match")
BadLoginError: Password does not match
--------------------------------------------------------------------------------
DEBUG:deluge:_on_login_fail(): [Failure instance: Traceback (failure with no frames): <class 'deluge.ui.client.DelugeRPCError'>: <deluge.ui.client.DelugeRPCError object at 0x7f58263f6150>
]
DEBUG:deluge:on_connect_fail: [Failure instance: Traceback (failure with no frames): <class 'deluge.ui.client.DelugeRPCError'>: <deluge.ui.client.DelugeRPCError object at 0x7f58263f6150>
]
INFO:deluge:Connection lost to daemon at 127.0.0.1:58846 reason: Connection was closed cleanly.
调试:洪水:ConfigManager已启动。。
信息:洪水:在127.0.0.1:58846连接到守护程序。。
信息:洪水:已在127.0.0.1:58846连接到守护程序。。
错误:洪水:收到RPCError消息!
--------------------------------------------------------------------------------
RPCRequest:daemon.login(本地客户端,f4f86361c7b9443464d0078f8d7c012e2ed63ce9)
--------------------------------------------------------------------------------
文件“/usr/lib/python2.7/dist packages/flouge/core/rpcserver.py”,第259行,在分派中
ret=component.get(“AuthManager”).authorize(*args,**kwargs)
文件“/usr/lib/python2.7/dist-packages/flouge/core/authmanager.py”,第93行,在authorize中
引发BadLogin错误(“密码不匹配”)
BadLogin错误:密码不匹配
--------------------------------------------------------------------------------
调试:洪水:_on_login_fail():[故障实例:回溯(没有帧的故障)::
]
调试:洪水:on\u connect\u fail:[故障实例:回溯(没有帧的故障)::
]
信息:洪水:在127.0.0.1:58846与守护程序的连接丢失原因:连接已完全关闭。
啊,这是一个很好的选择
添加此选项以抑制消息:
import logging
logging.getLogger('deluge').addHandler(logging.NullHandler())
或将所有内容写入stderr:
import logging, sys
logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)
这确实解决了问题。没有更多的错误,但现在我有30多个“cron”进程正在运行,并且日志文件没有显示任何输出。谢谢您的反馈,呃,@user3787700。我已经添加了另一节,它将向stderr写入错误,而不是抛出错误,以帮助调试。感谢您的快速回复。感谢你的努力!我已经编辑了我的问题,密码错误,请看一看。
import logging, sys
logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)