Pyro: ProtocolError('connection failed')

J

jamitwidme

Hello everyone
Can someone help me fix this problem?

I am using an example from Pyro(Python Remote Object) website
directly.
It is the last example from
http://pyro.sourceforge.net/manual/8-example.htm

I have two computers to run Server and Client.
############################################
server.py

import Pyro.naming
import Pyro.core
from Pyro.errors import PyroError,NamingError


###### testclass Pyro object

class testclass(Pyro.core.ObjBase):
def mul(s, arg1, arg2): return arg1*arg2
def add(s, arg1, arg2): return arg1+arg2
def sub(s, arg1, arg2): return arg1-arg2
def div(s, arg1, arg2): return arg1/arg2

###### main server program

def main():
Pyro.core.initServer()
daemon = Pyro.core.Daemon()
# locate the NS
locator = Pyro.naming.NameServerLocator()
print 'searching for Name Server...'
ns = locator.getNS(host='drizzle.des.hep.uiuc.edu', port=9090)
daemon.useNameServer(ns)

# connect a new object implementation (first unregister
previous one)
try:
# 'test' is the name by which our object will be known
to the outside world
ns.unregister('test')
except NamingError:
pass

# connect new object implementation
daemon.connect(testclass(),'test')

# enter the server loop.
print 'Server object "test" ready.'
daemon.requestLoop()

if __name__=="__main__":
main()

###################################

###################################
client.py

import Pyro.naming, Pyro.core
from Pyro.errors import NamingError

# locate the NS
locator = Pyro.naming.NameServerLocator()
print 'Searching Name Server...',
ns = locator.getNS(host='drizzle.des.hep.uiuc.edu',port=9090)

# resolve the Pyro object
print 'finding object'
try:
URI=ns.resolve('test')
print 'URI:',URI
except NamingError,x:
print 'Couldn\'t find object, name server says:',x
raise SystemExit

# create a proxy for the Pyro object, and return that
test = Pyro.core.getProxyForURI(URI)

print test.mul(111,9)
print test.add(100,222)
print test.sub(222,100)
print test.div(2.0,9.0)
print test.mul('*',10)
print test.add('String1','String2')
#######################################

It does not matter which computer Pyro NameServer is located.
When Server and Client are in a same computer, it works perfectly
fine.
But whenever Server and Client run in different computers, I get a
following error message.


########################################
Pyro Client Initialized. Using Pyro V3.7
Searching Name Server... finding object
URI: PYRO://127.0.0.1:7888/7f000001193649ab6a89d5592bc843bb
Traceback (most recent call last):
File "client.py", line 22, in <module>
print test.mul(111,9)
File "/usr/local/lib/python2.5/site-packages/Pyro/core.py", line
390, in __call__
return self.__send(self.__name, args, kwargs)
File "/usr/local/lib/python2.5/site-packages/Pyro/core.py", line
467, in _invokePYRO
self.adapter.bindToURI(self.URI)
File "/usr/local/lib/python2.5/site-packages/Pyro/protocol.py", line
255, in bindToURI
raise ProtocolError('connection failed')
Pyro.errors.ProtocolError: connection failed
########################################

Thanks a lot.
 
D

Diez B. Roggisch

Hello everyone
Can someone help me fix this problem?

I am using an example from Pyro(Python Remote Object) website
directly.
It is the last example from
http://pyro.sourceforge.net/manual/8-example.htm

I have two computers to run Server and Client.
############################################
server.py

import Pyro.naming
import Pyro.core
from Pyro.errors import PyroError,NamingError


###### testclass Pyro object

class testclass(Pyro.core.ObjBase):
def mul(s, arg1, arg2): return arg1*arg2
def add(s, arg1, arg2): return arg1+arg2
def sub(s, arg1, arg2): return arg1-arg2
def div(s, arg1, arg2): return arg1/arg2

###### main server program

def main():
Pyro.core.initServer()
daemon = Pyro.core.Daemon()
# locate the NS
locator = Pyro.naming.NameServerLocator()
print 'searching for Name Server...'
ns = locator.getNS(host='drizzle.des.hep.uiuc.edu', port=9090)
daemon.useNameServer(ns)

# connect a new object implementation (first unregister
previous one)
try:
# 'test' is the name by which our object will be known
to the outside world
ns.unregister('test')
except NamingError:
pass

# connect new object implementation
daemon.connect(testclass(),'test')

# enter the server loop.
print 'Server object "test" ready.'
daemon.requestLoop()

if __name__=="__main__":
main()

###################################

###################################
client.py

import Pyro.naming, Pyro.core
from Pyro.errors import NamingError

# locate the NS
locator = Pyro.naming.NameServerLocator()
print 'Searching Name Server...',
ns = locator.getNS(host='drizzle.des.hep.uiuc.edu',port=9090)

# resolve the Pyro object
print 'finding object'
try:
URI=ns.resolve('test')
print 'URI:',URI
except NamingError,x:
print 'Couldn\'t find object, name server says:',x
raise SystemExit

# create a proxy for the Pyro object, and return that
test = Pyro.core.getProxyForURI(URI)

print test.mul(111,9)
print test.add(100,222)
print test.sub(222,100)
print test.div(2.0,9.0)
print test.mul('*',10)
print test.add('String1','String2')
#######################################

It does not matter which computer Pyro NameServer is located.
When Server and Client are in a same computer, it works perfectly
fine.
But whenever Server and Client run in different computers, I get a
following error message.


########################################
Pyro Client Initialized. Using Pyro V3.7
Searching Name Server... finding object
URI: PYRO://127.0.0.1:7888/7f000001193649ab6a89d5592bc843bb
Traceback (most recent call last):
File "client.py", line 22, in <module>
print test.mul(111,9)
File "/usr/local/lib/python2.5/site-packages/Pyro/core.py", line
390, in __call__
return self.__send(self.__name, args, kwargs)
File "/usr/local/lib/python2.5/site-packages/Pyro/core.py", line
467, in _invokePYRO
self.adapter.bindToURI(self.URI)
File "/usr/local/lib/python2.5/site-packages/Pyro/protocol.py", line
255, in bindToURI
raise ProtocolError('connection failed')
Pyro.errors.ProtocolError: connection failed
########################################

Thanks a lot.

THis is just a guess - but it seems that somehow you don't bind your
pyro objects to the NIC's IP address, but to localhost (127.0.0.1) -
which of course won't work. That never happened to me though, try and
see the pyro docs on how to prevent/control to which IP a proxy is bound.

Diez
 
I

Irmen de Jong

Diez said:
THis is just a guess - but it seems that somehow you don't bind your
pyro objects to the NIC's IP address, but to localhost (127.0.0.1) -
which of course won't work. That never happened to me though, try and
see the pyro docs on how to prevent/control to which IP a proxy is bound.

This problem has been discussed quite a bit on the Pyro mailinglist. What's happening is
that Pyro is indeed binding the server on the loopback adapter (making it invisible from
the outside). It does this because of what I (and several others) believe to be a bug in
the default hosts file of many linux distributions: the local hostname resolves to the
loopback adapter's address 127.0.0.1 instead of a sensible IP address.

Pyro provides some ways to work around this issue, if you can't or won't fix the
/etc/hosts file.

--irmen


PS I've replied to the original poster by private email conversation. I'm filtering
newsgroups posts that originate from google groups, hence I only saw this message
because of Diez's reply.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,058
Latest member
QQXCharlot

Latest Threads

Top