Re: Pyro 4 help - please? :)

Irmen de Jong <[email protected]> Tue, 21 Oct 2014 21:06:14 +0200
Newsgroups gmane.comp.python.pyro
Message-ID <[email protected]>
Hello,

Because the original mail wasn't sent to the mailing list I'm taking the liberty to copy
part of the context of Aaron's questions here again:

"
I have a Windows 7 64-bit machine that I’m using to host my main application. I will
have 6 Raspberry Pis attached via Ethernet to a router that the Windows box is also
attached to (I only have 1 setup right now – which is good enough for my dev purposes).
I have a working samba share between the pi and the windows box.

On the  Windows 7 machine I have Python 2.7.6, and Pyro4 (4.28). My Windows PC is names
‘GOATS’ (don’t ask)

Along with hosting my main application (which I understand will be the pyro client to
each of the pis serving their individual functions) the windows box is also the name
server for the application.
"

On to Aaron's mail:

On 21-10-2014 20:20, Aaron Wylie wrote:

>> 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?

Well if you want to use the hostname ("GOATS") as part of the Uri you have to make sure
your Pi's can resolve that to the ip address of the windows box. The easiest way to do
that is by putting it in the hosts file of each Pi unit, I guess. Setting up a working
dns is arguably better but perhaps overkill for your situation



>>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()

That is valid but problematic code due to the daemon binding on localhost by default.
I'm reviewing the docs on this right now and think it could perhaps be improved a bit to
make this clearer  https://github.com/irmen/Pyro4/issues/63


>>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?

You should not have to deal with these methods directly, they're pretty low level.
What you could do is simply binding the daemon on the pi's externally visible interface.

So say the ip address of the pi is 192.168.1.147 you could do:

daemon = Pyro4.Daemon(host="192.168.1.147")

and carry on with the rest of your code as given. Substitute the ip address with the
pi's hostname if that resolves correctly. If you don't want to hardcode the ip address
and the hostname doesn't resolve correctly, then you can use
Pyro4.socketutil.getIpAddress("") or Pyro4.socketutil.getIpAddress("hostnameofthePi").



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

You'll have to enable them first to make them appear. Usually it will be a file called
Pyro.log in the current directory, but that's configurable:
http://pythonhosted.org/Pyro4/tipstricks.html#logging

(adapt the unix shell syntax to windows cmd.exe syntax when on your windows box)



>>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.

Correct; fix the dns or use ip address directly


> 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?

It is. The small change you need to make is described earlier. I'll have a look at the
docs to see if I can improve them a little on this matter.  I guess the info is too
fragmented, and not really explained in the tutorial paragraph either (that does mention
it).


Irmen


------------------------------------------------------------------------------
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