Re: Pyro 4 help - please? :)

"Aaron Wylie" <[email protected]> Tue, 21 Oct 2014 11:20:27 -0700
Newsgroups gmane.comp.python.pyro
Message-ID <[email protected]>
Hi Irmen. See me comments below, lines starting with 'From Aaron:'

-----Original Message-----
From: Irmen de Jong [mailto:[email protected]] 
Sent: Tuesday, October 21, 2014 10:04 AM
To: Aaron Wylie
Subject: Re: Pyro 4 help - please? :)

On 21-10-2014 7:04, Aaron Wylie wrote:
> Hi Irmen,
> 
>  
> 
> I've noticed that you are quite actively answering pyro4 support 
> questions. Glad to make your acquaintance J
> 

Hello Aaron
yeah well I'm morally obligated to do that, being Pyro's only developer :)

>From Aaron: Karma points.

> Then in another cmd terminal on the same machine "pyro4-nsc list":
> 
> --------START LIST
> 
> Pyro.NameServer --> PYRO:Pyro.NameServer@GOATS:9090
> 
> --------END LIST

Good, this means the name server runs correctly on the windows box and you
can reach it, on the same box, from a Pyro client.

>From Aaron: If by 'client', you mean another command prompt on the same
computer, yes, looks all good. Of course, what I can't do is reach my server
function hosted by the pi, from the client.py script I run from the windows
box hosting the name server. 


> Now, when I putty into the pi, I run my python server code which 
> includes a class named
> "Frequency()":
> 
>  
> 
> daemon = Pyro4.Daemon()
> 
> ns = Pyro4.locateNS(host="GOATS", port=9090)
> 
> uri = daemon.register(Frequency())
> 
> ns.register("frequency", uri)
> 
> daemon.requestLoop()
> 
>  
> 
> I get a traceback that ends with "Pyro4.errors.NamingError: Failed to 
> locate the nameserver". When I substitute the i.p. of the nameserver 
> computer instead of "GOATS", it finds it perfectly.

At what line does the error occur?
Definitely some form of DNS issue going on here, what happens when you run
the locateNS call on your windows box itself?  Can you 'ping GOATS' from the
pi? Maybe it works better when you use a fully qualified domain name
("goats.mynetwork.lan" whatever it is)?

>From Aaron: It chokes on this line "Pyro4.locateNS(host="GOATS", port=9090)"
when running from the pi. The error is "Pyro4.errors.NamingError: Failed to
locate the nameserver". I can run the locateNS call on my windows box, with
the name 'GOATS', and it seems to be working. I did a 'pyro4-nsc list' on
the same machine and I see my frequency function listed. I've looked at my
computer properties and it only has "GOATS" listed for both 'computer name'
and 'full computer name'. Is there something I need to enter into my hosts
file? Should this matter?


> I've been using this method to this point, although, I think that 
> calling on the host name is a better solution. So my server.py code 
> now contains "ns = Pyro4.locateNS(host="192.168.1.147", port=9090)"

That should not be needed indeed, it's better to be able to use the
hostname.

>From Aaron: Agreed


 > Back on the windows machine, I do a 'pyro4-nsc list' and I get:
> 
> --------START LIST
> 
> Pyro.NameServer --> PYRO:Pyro.NameServer@GOATS:9090
> 
> frequency --> 
> PYRO:obj_473e96769fcc49549298e8675918ace6@localhost:52898
> 
> --------END LIST

Ok this means that you *have* been able to talk to the name server from the
pi, otherwise the frequency object would not be present in the registry.
That contradicts your earlier statement that you get a NamingError.

>From Aaron: I was only able to see the object here on the nameserver by
using the IP address in the locateNS code on the pi, not by using 'GOATS' as
we've been attempting to figure out.


> Perfect!

No not really, as you can see the Uri of the frequency object contains a
reference to 'localhost'. That is almost certainly not correct because the
object is living on one of your pi's. You have to bind the daemon on the pi
on a different network adapter so as to fix the uri references that it
generates. See:

http://pythonhosted.org/Pyro4/servercode.html#network-adapter-binding


>From Aaron: Ok, that makes sense. So, just to clarify, in the function
server code I have hosted by the pi I have (and of course the reference to
'GOATS' doesn't work yet):

daemon = Pyro4.Daemon()
ns = Pyro4.locateNS(host="GOATS", port=9090)
uri = daemon.register(Frequency())
ns.register("frequency", uri)
daemon.requestLoop()

>From Aaron: Do I need to use Pyro4.socketutil.getIpAddress() or
Pyro4.socketutil.getInterfaceAddress() somewhere in there as well? If so,
can you show me how?


> So, now where I'm stuck is running my client script (which is on the 
> main Windows machine hosting the name server. My script is simply:
> 
>  
> 
> import Pyro4
> 
> freq = Pyro4.Proxy("PYRONAME:frequency")

This one should work just fine

>From Aaron: Cool, that's what we're going to shoot for

> #freq = 
> Pyro4.Proxy("PYRO:obj_473e96769fcc49549298e8675918ace6@localhost:52898
> ")

This one cannot possibly work because it would try to connect to the object
on GOATS
(localhost) where it doesn't exist

>From Aaron: Gotcha

> #freq = 
> Pyro4.Proxy("PYRO:obj_473e96769fcc49549298e8675918ace6-Q0ErXNX1RuacWjgR6IliTw@public.gmane.org:5
> 2898")

This one *could* work if and only if 192.168.1.147 is the IP adress of your
pi and the daemon on it is running on port 52898, *and is not bound to the
local loopback network adapter*.

>From Aaron: Yup, I see what you mean.


> The error I return each ways is:
> "Pyro4.errors.CommunicationError: cannot connect: [Errno 10061] No 
> connection could be made because the target machine actively refused it"

My guess is that this is because of the above 'localhost' naming issue of
the daemon on your pi's. Bind it on the actual hostname or externally
reachable network address and you should be fine.

>From Aaron: Ok. In this current email I've asked about how to use
Pyro4.socketutil.getIpAddress() in the code on the pi. I'll apply the
feedback you'll give me regarding this.

Remember: you can enable the logging and see what Pyro is trying to do and
what machines it is trying to gain access to! It also helps to just print
out the Proxy or Uri object and check if the hostname+port is what you are
expecting it to be, in case of these kinds of issues.

>From Aaron: I was poking around for some logs yesterday. Where would they be
hanging out?


> After looking a long time at other people's issues, my latest 
> conclusion is that that might be a IPv4/IPv6 issue? I've looked in my 
> windows 'hosts' file and I don't have an active "127.0.0.1 localhost" 
> entry. I've shut my windows firewall off (which may not be of 
> consequence seeing at the client and the nameserver are on the same 
> machine)

Nah, Pyro is using ipv4 unless you tell it explicitly to use ipv6.
But if your dns resolves 'localhost' or 'GOAT' only to an ipv6 address, you
might be in trouble here.

>From Aaron: When I run an ipconfig on my windows box, I see my ip associated
with ipv4. All clear there.


>From Aaron: So, now that I've gone through this with you, maybe I'm seeing 2
issues. 
1.) the pi cannot see and resolve "GOATS" and therefore cannot register a
function on the windows box without using the IP address of the windows box.

2.) when the function on the pi registers with the windows name server (via
the ip address), the object appears to run on localhost, not on the pi. This
comes down to a network adapter binding issue which I need a bit of
direction on.
Is this your take?


Regards
Irmen de Jong


PS  my preference is to use Pyro's mailing list for discussions
>From Aaron: I've sent this back through the mailing list (ccing you just in
case). Was this correct?




------------------------------------------------------------------------------
Comprehensive Server Monitoring with Site24x7.
Monitor 10 servers for $9/Month.
Get alerted through email, SMS, voice calls or mobile push notifications.
Take corrective actions from your mobile device.
http://p.sf.net/sfu/Zoho