TypeError:不可用类型:python的'dict'

时间:2015-06-25 16:48:47

标签: python

我正在尝试在Deluge torrent客户端上设置一个cron自动删除文件,代码如下:

import sys
import os
import subprocess
import logging
from datetime import datetime, date, time, timedelta
from deluge.ui.client import client
import deluge.component as component
from deluge.log import LOG as log
from twisted.internet import reactor
logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)

def printData(dresult):
    if dresult:
        print "Command executed with result: ", dresult
    else:
       sys.stderr.write(str(failure))

def on_connect_success(result):
    def on_get_torrent_value(value):
        for torrent in value:
             seedtime = datetime.fromtimestamp(value[torrent]["seeding_time"]) - datetime.fromtimestamp(0)
             if value[torrent]["label"] in labels and value[torrent]["is_finished"] == True and seedtime >= timedelta(hours = totalseedtime):
                   --- multiple of commands ---
        client.disconnect()
        reactor.stop()

    client.core.get_torrents_status({}, ["name", "is_finished", "save_path", "seeding_time", "label"]).addCallback(on_get_torrent_value)
    client.core.remove_torrent({}, remove_data = False).addCallbacks(printData)

d.addCallback(on_connect_success)

def on_connect_fail(result):
    print "result:", result

d.addErrback(on_connect_fail)

reactor.run()

执行时,返回调试日志:

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: core.remove_torrent({}, remove_data=False)
--------------------------------------------------------------------------------
  File "/usr/local/lib/python2.7/dist-packages/deluge-1.3.11-py2.7.egg/deluge/core/rpcserver.py", line 299, in dispatch
    ret = self.factory.methods[method](*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/deluge-1.3.11-py2.7.egg/deluge/core/core.py", line 326, in remove_torrent
    return self.torrentmanager.remove(torrent_id, remove_data)
  File "/usr/local/lib/python2.7/dist-packages/deluge-1.3.11-py2.7.egg/deluge/core/torrentmanager.py", line 568, in remove
    torrent_name = self.torrents[torrent_id].get_status(["name"])["name"]

TypeError: unhashable type: 'dict'
--------------------------------------------------------------------------------
Unhandled error in Deferred:
Unhandled Error
Traceback (most recent call last):
Failure: deluge.ui.client.DelugeRPCError: <deluge.ui.client.DelugeRPCError object at 0x1aeae50>
INFO:deluge:Connection lost to daemon at 127.0.0.1:58846 reason: Connection to the other side was lost in a non-clean fashion: Connection lost.

据我所知,传递给client.core.remove_torrent的dic在格式上有些不对劲,但不知道如何修复它。非常感谢任何帮助!非常感谢提前。

1 个答案:

答案 0 :(得分:0)

您不能使用dict作为密钥(它是可变的 - 请参阅http://192.168.1.2/xampp的说明以获得解释)。

看起来你应该传递一些torrent_id来移除,无论如何,它必须是可以清除的东西 - 即不是dict