我有一个cronjob的python脚本,用于删除超过3天的种子。如果我从终端运行它,这个脚本有效,但是crontab给了我这个错误No handlers could be found for logger "deluge"
。有谁能告诉我如何解决这个问题?
这是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()
这是我从终端运行它时的输出:
mou@mou-lanister:~/scripts$ ./cpmanagertest.py
[+] Connection was successful!
[i] Current unix time is 1404169193
[i] Filtering torrents older than Sun Jun 29 18:59:53 2014
[i] Skipping Mon Jun 30 03:57:52 2014: War.Horse.2011.1080p.MKV.x264.AC3.DTS.NL.Subs from /home/mou/CPDownloads/
[i] Skipping Mon Jun 30 04:00:00 2014: The Legend Of Hercules 2014 1080p BluRay DTS x264 PublicHD from /home/mou/CPDownloads/
[+] Removed Sun Jun 29 16:52:16 2014: Paranormal.Activity.The.Marked.Ones.2014.EXTENDED.1080p.BluRay.x264-SPARKS [PublicHD] from /home/mou/CPDownloads/
[+] Removed Sun Jun 29 17:07:12 2014: The.Hobbit.The.Desolation.Of.Smaug.2013.1080p.BluRay.DTS.x264-PublicHD from /home/mou/CPDownloads/
[+] Removed Sun Jun 29 17:22:08 2014: thor the dark world 2013 1080p bluray x264 sparks publichd from /home/mou/CPDownloads/
[+] Removed Sun Jun 29 16:24:32 2014: The.Conjuring.2013.1080p.BluRay.x264-ALLiANCE [PublicHD] from /home/mou/CPDownloads/
[+] Removed Sun Jun 29 17:00:48 2014: Her.2013.1080p.BluRay.x264-SPARKS [PublicHD] from /home/mou/CPDownloads/
[+] Removed Sun Jun 29 17:20:00 2014: Rush 2013 1080p 60fps BluRay x264-zologne from /home/mou/CPDownloads/
[+] Removed Sun Jun 29 17:22:08 2014: Escape.Plan.2013.1080p.BluRay.DTS-HD.MA.7.1.x264-PublicHD from /home/mou/CPDownloads/
[+] Removed Sun Jun 29 17:05:04 2014: The.Fifth.Estate.2013.1080p.BluRay.x264-SPARKS [PublicHD] from /home/mou/CPDownloads/
[+] Removed 8 torrents -- Skipped 2 torrents -- Seeding 0 torrents
[i] Client disconnected.
这是crontab作业的日志:
没有找到处理程序“logluger”的处理程序
没有处理程序可以找到记录器“洪水”
没有处理程序可以找到记录器“洪水”
没有处理程序可以找到记录器“洪水”
没有处理程序可以找到记录器“洪水”
没有处理程序可以找到记录器“洪水”
没有处理程序可以找到记录器“洪水”
没有处理程序可以找到记录器“洪水”
没有处理程序可以找到记录器“洪水”
没有处理程序可以找到记录器“洪水”
没有处理程序可以找到记录器“洪水”
没有找到处理程序“logluger”
添加调试代码后,出现以下错误:
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.
答案 0 :(得分:2)
啊,它是warts of Python之一。
添加此内容以禁止显示消息:
import logging
logging.getLogger('deluge').addHandler(logging.NullHandler())
或者写一切给stderr:
import logging, sys
logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)