Reputation: 302
Say in server.py
import rpyc
class MyError(Exception):
def __init__(self, message):
super(MyError, self).__init__(message)
self.error = message
def foo1(self):
self.error_type = 1
def foo2(self):
self.error_type = 2
class MyService(rpyc.Service):
def exposed_test(self):
e = MyError('error')
e.foo1()
return e
if __name__ == '__main__':
from rpyc.utils.server import ThreadPoolServer
server = ThreadPoolServer(MyService(), port=6000)
server.start()
In client.py
, I want to take different steps based on error_type
like this:
import rpyc
with rpyc.connect('localhost', 6000) as conn:
try:
raise conn.root.test()
except Exception as e:
if e.error_type == 1:
pass
else:
pass
However, the compiler says
Traceback (most recent call last):
File "C:/python/client.py", line 5, in <module>
raise conn.root.test()
TypeError: exceptions must derive from BaseException
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/python/client.py", line 7, in <module>
if e.error_type == 1:
AttributeError: 'TypeError' object has no attribute 'error_type'
How can I access the member variables of such objects? It didn't work even if I change Exception
to BaseException
.
Update:
I modified client.py
as:
import rpyc
with rpyc.connect('localhost', 6000) as conn:
e = conn.root.test()
print(e)
print(e.error_type)
.print(e)
got it right as it prints "error" but I still can't get e.error_type
Upvotes: 0
Views: 597