我一直在使用twisted来制作一个sftp服务器,但是在从我的ISFTPServer.openDirectory函数返回任何信息时遇到了问题。
例如
class MySFTPAdapter:
implements(filetransfer.ISFTPServer)
def openDirectory(self, path):
return ('test', 'drwxrwxrwx 1 ab cd 0 Apr 23 15:41 test', {'size': 0, 'uid': 1000, 'gid': 1000, 'mtime': 1366746069L, 'atime': 1366746069L, 'permissions': 511})失败,错误为
Traceback (most recent call last):
File "sftpserver.py", line 435, in dataReceived
f(data)
File "/usr/lib/python2.6/dist-packages/twisted/conch/ssh/filetransfer.py", line 265, in packet_OPENDIR
d.addCallback(self._cbOpenDirectory, requestId)
File "/usr/lib/python2.6/dist-packages/twisted/internet/defer.py", line 260, in addCallback
callbackKeywords=kw)
File "/usr/lib/python2.6/dist-packages/twisted/internet/defer.py", line 249, in addCallbacks
self._runCallbacks()
--- <exception caught here> ---
File "/usr/lib/python2.6/dist-packages/twisted/internet/defer.py", line 441, in _runCallbacks
self.result = callback(self.result, *args, **kw)
File "/usr/lib/python2.6/dist-packages/twisted/conch/ssh/filetransfer.py", line 269, in _cbOpenDirectory
handle = str(hash(dirObj))
exceptions.TypeError: unhashable type: 'dict'异常框架局部变量是;
{'val': ('test', 'drwxrwxrwx 1 ab cd 0 Apr 23 15:41 test', {'size': 0, 'uid': 1000, 'gid': 1000, 'mtime': 1366746069L, 'atime': 1366746069L, 'permissions': 511})}有谁知道我做错了什么事吗?
发布于 2013-05-01 02:58:54
您的openDirectory实现
def openDirectory(self, path):
return ('test',
'drwxrwxrwx 1 ab cd 0 Apr 23 15:41 test',
{'size': 0, 'uid': 1000, 'gid': 1000, 'mtime': 1366746069L,
'atime': 1366746069L, 'permissions': 511})返回由三个元素组成的元组。从接口文档中:
This method returns an iterable object that has a close() method,
or a Deferred that is called back with same.
The close() method is called when the client is finished reading
from the directory. At this point, the iterable will no longer
be used.
The iterable should return triples of the form (filename,
longname, attrs) or Deferreds that return the same. The
sequence must support __getitem__, but otherwise may be any
'sequence-like' object. 您返回的元组听起来像这里讨论的迭代器的一个元素,而不是整个返回值。
尝试如下所示:
def openDirectory(self, path):
yield ('test',
'drwxrwxrwx 1 ab cd 0 Apr 23 15:41 test',
{'size': 0, 'uid': 1000, 'gid': 1000, 'mtime': 1366746069L,
'atime': 1366746069L, 'permissions': 511})现在您有了一个生成器--它是一个带有close方法的迭代器--它的元素是文档中描述的三元组。
https://stackoverflow.com/questions/16300262
复制相似问题