| Tomer Filiba tomerfiliba.com |
why can't use items for dict object ?
thanks.
[root@deploy client]# python client.py
type(s) : <netref class '__builtin__.dict'>
print dir(s): ['__class__', '__cmp__', '__contains__', '__delattr__', '__delitem__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__gt__', '__hash__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__', 'clear', 'copy', 'fromkeys', 'get', 'has_key', 'items', 'iteritems', 'iterkeys', 'itervalues', 'keys', 'pop', 'popitem', 'setdefault', 'update', 'values']
print s: {'10.216.250.230': ' 15:04:41 up 41 days, 22:47, 2 users, load average: 0.00, 0.00, 0.00\nUSER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT\nroot pts/0 10.1.206.16 14:04 52:17 0.24s 0.15s python server.p\nroot pts/1 10.1.206.16 14:12 52:11 0.03s 0.03s -bash', '127.0.0.1': ' 15:04:33 up 36 days, 3:50, 7 users, load average: 0.00, 0.00, 0.00\nUSER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT\nroot pts/0 10.1.206.16 09:20 3:29 1.87s 1.79s vim proxy.py\nroot pts/1 10.1.206.16 09:20 1:04m 0.09s 0.05s vim server.py\nroot pts/2 10.1.206.16 09:27 38:51 0.29s 0.29s python\nroot pts/3 10.1.206.16 13:45 1:04m 0.19s 0.18s python server.p\nroot pts/4 10.1.206.16 13:46 1:04m 0.21s 0.19s python proxy.py\nroot pts/5 10.1.206.16 13:50 32.00s 0.38s 0.37s vim client.py\nroot pts/6 10.1.206.16 13:50 0.00s 0.17s 0.11s python client.p'}
Traceback (most recent call last):
File "client.py", line 24, in <module>
for k,v in s.items():
File "/usr/lib/python2.6/site-packages/rpyc-3.2.3-py2.6.egg/rpyc/core/netref.py", line 150, in __getattr__
return syncreq(self, consts.HANDLE_GETATTR, name)
File "/usr/lib/python2.6/site-packages/rpyc-3.2.3-py2.6.egg/rpyc/core/netref.py", line 71, in syncreq
return conn.sync_request(handler, oid, *args)
File "/usr/lib/python2.6/site-packages/rpyc-3.2.3-py2.6.egg/rpyc/core/protocol.py", line 438, in sync_request
raise obj
AttributeError: cannot access 'items'
========= Remote Traceback (1) =========
Traceback (most recent call last):
File "/usr/lib/python2.6/site-packages/rpyc-3.2.3-py2.6.egg/rpyc/core/protocol.py", line 300, in _dispatch_request
res = self._HANDLERS[handler](self, *args)
File "/usr/lib/python2.6/site-packages/rpyc-3.2.3-py2.6.egg/rpyc/core/protocol.py", line 538, in _handle_getattr
return self._access_attr(oid, name, (), "_rpyc_getattr", "allow_getattr", getattr)
File "/usr/lib/python2.6/site-packages/rpyc-3.2.3-py2.6.egg/rpyc/core/protocol.py", line 501, in _access_attr
raise AttributeError("cannot access %r" % (name,))
AttributeError: cannot access 'items'
==================== CODE ================
server.py code
class ProxyServer(Service):
def RunSingleJob(self,CMD=None,LIST=None):
result = {}
for h in LIST:
try:
c = connect(h,20000)
result[h] = c.root.ExecCmd(CMD)
c.close()
except Exception,e:
print e
return result
def exposed_MadeJob(self,CMD=None,LIST=None,TYPE=0):
if TYPE == 0:
## single sys command
return self.RunSingleJob(CMD,LIST)
if TYPE == 1:
## mulit sys command
return self.RunMultiJob(CMD,LIST)
if TYPE == 2:
## define batch command for a job
pass
s = ThreadedServer(ProxyServer,port=20001)
s.start()
---------------------------------------
client.py code
Host = '127.0.0.1'
Port = 20001
HostList = ['127.0.0.1','10.216.250.230']
Type = 0
cmd = "w"
result = {}
c = rpyc.connect(Host,Port)
s = c.root.MadeJob(CMD=cmd,LIST=HostList,TYPE=Type)
print type(s)
print dir(s)
print s
for k,v in s.items():
print "Host : %s " % k
print "[ %s ]" % v
c.close()
--
---
You received this message because you are subscribed to the Google Groups "rpyc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rpyc+uns...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.