python – Pyro4:找不到名称服务器

前端之家收集整理的这篇文章主要介绍了python – Pyro4:找不到名称服务器前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我是 Python和Pyro4的新手.所以我尝试按照此页面 Pyro – Python Remote Objects – 4.41的第二个示例,但是当我运行服务器时抛出此异常:
Traceback (most recent call last):
  File "greeting-server.py",line 10,in <module>
    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
>点子安装https://pypi.python.org/packages/2.7/s/serpent/serpent-
1.7 py2.py3-NONE-any.whl

运行这个例子

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

解决方法

这项工作对我来说:

首先在另一个终端运行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做过,因为你看到这个程序改变了

原文链接:https://www.f2er.com/python/186093.html

猜你在找的Python相关文章