Re: Newbie: AttributeError: 'module' object has no attribute 'Client'
Todd Williamson <[email protected]>
| Newsgroups | gmane.comp.python.pyro |
|---|---|
| Message-ID | <CABR0oaj66DmnK6v_Kq+mrEK5EGwLz3gSQoeXQ-0jAg-fSxSdgw@mail.gmail.com> |
The problem is that the server has no knowledge of the class Client. Add an import client statement into server.py. Also, move all the code in global scope in client.py into a main method and start things up as you do in server.py. On Sun, May 27, 2012 at 12:44 AM, Schneider <[email protected]> wrote: > Hi all, > > I am just getting started with Pyro4, so please forgive me if I am doing > something very stupid. > I want a client to register with a server, much like the chatter example, > which works nicely. However, my code gives the error : > > AttributeError: 'module' object has no attribute 'Client' > > The server: > import Pyro4 > > class Server(object): > def ping(self): > return 'pong' > def join(self, callback): > self.callback = callback > return "connected" > > def main(): > try: > with Pyro4.core.Daemon() as daemon: > with Pyro4.naming.locateNS() as ns: > uri = daemon.register(Server()) > ns.register("test.server", uri) > # enter the service loop. > daemon.requestLoop() > except Pyro4.errors.NamingError, e: > print e > > if __name__ == "__main__": > main() > print "Done" > > The client: > > import Pyro4 > from Pyro4 import threadutil > > class Client(object): > def __init__(self): > self.server = Pyro4.core.Proxy('PYRONAME:test.server') > print self.server > def start(self): > print self.server.ping() > self.server.join(self) > while True: > line = raw_input('> ').strip() > if line=='/q': > break > > class DaemonThread(threadutil.Thread): > def __init__(self, instance): > threadutil.Thread.__init__(self) > self.instance = instance > def run(self): > with Pyro4.core.Daemon() as daemon: > daemon.register(self.instance) > daemon.requestLoop() > > client = Client() > daemonthread=DaemonThread(client) > daemonthread.start() > client.start() > print('Exit.') > > Output: > > <Pyro4.core.Proxy at 0x18cd310, not connected, for PYRONAME:test.server> > pong > Traceback (most recent call last): > File "C:\Users\schnef\workspace\clipserp\src\server\client.py", line 28, > in <module> > client.start() > File "C:\Users\schnef\workspace\clipserp\src\server\client.py", line 10, > in start > self.server.join(self) > File "C:\Python27\lib\site-packages\Pyro4\core.py", line 149, in __call__ > return self.__send(self.__name, args, kwargs) > File "C:\Python27\lib\site-packages\Pyro4\core.py", line 289, in > _pyroInvoke > raise data > AttributeError: 'module' object has no attribute 'Client' > > I get the same error on Windows with python 2.7 and on Debian with Python > 2.6. I have Pyro 4.1.4 installed. > I am lost, so any help would be appreciated very much, > > TIA > > Frans > > > > ------------------------------------------------------------------------------ > Live Security Virtual Conference > Exclusive live event will cover all the ways today's security and > threat landscape has changed and how IT managers can respond. Discussions > will include endpoint security, mobile security and the latest in malware > threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ > _______________________________________________ > Pyro-core mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/pyro-core > ------------------------------------------------------------------------------ Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ _______________________________________________ Pyro-core mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/pyro-core