当前位置:  开发笔记 > 编程语言 > 正文

Pyro4:找不到名称服务器

如何解决《Pyro4:找不到名称服务器》经验,为你挑选了1个好方法。

我是Python和Pyro4的新手.所以我尝试按照本页的第二个例子Pyro - Python Remote Objects - 4.41,但是当我运行服务器时抛出这个异常:

Traceback (most recent call last):
  File "greeting-server.py", line 10, in 
    ns = Pyro4.locateNS()                  # find the name server
  File "/usr/lib/python2.7/dist-packages/Pyro4/naming.py", line 344, in locateNS
    raise e
Pyro4.errors.NamingError: Failed to locate the nameserver

代码服务器:

# saved as greeting-server.py
import Pyro4

class GreetingMaker(object):
    def get_fortune(self, name):
        return "Hello, {0}. Here is your fortune message:\n" \
               "Tomorrow's lucky number is 12345678.".format(name)

daemon = Pyro4.Daemon()                # make a Pyro daemon
ns = Pyro4.locateNS()                  # find the name server
uri = daemon.register(GreetingMaker)   # register the greeting maker as a Pyro object
ns.register("example.greeting", uri)   # register the object with a name in the name server

print("Ready.")
daemon.requestLoop()                   # start the event loop of the server to wait for calls

首先在另一个终端运行pyro-ns:

$pyro-ns
*** Pyro Name Server ***
Name server listening on: ('0.0.0.0', 9090)

WARNING: daemon bound on hostname that resolves to loopback address 127.0.x.x 

URI is: PYRO://127.0.1.1:9090/7f0001011d2a21ca9fb63702dd216e1143
URI written to: /home/guille/Documents/pyro examples/Pyro4-master/examples/banks/Pyro_NS_URI
Name Server started.

备注:我在Debian 8上工作,我安装了:

sudo apt-get install pyro4

sudo apt-get install python2-pyro4

pip install https://pypi.python.org/packages/2.7/s/serpent/serpent- 1.7-py2.py3-none-any.whl

运行这个例子

也许我错过了什么.任何想法为什么这不起作用,或者我做错了什么?提前致谢.



1> Cyberguille..:

这项工作对我来说:

首先在另一个终端运行python -m Pyro4.naming:

Not starting broadcast server for localhost.
NS running on localhost:9090 (127.0.0.1)
URI = PYRO:Pyro.NameServer@localhost:9090

而不是pyro-ns我之前为pyro4做过,因为你看到这个程序改变了

推荐阅读
小白也坚强_177
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有