week06 07 创建RPC SERVER 换个镜像安装下载

RPC server 使用python类库

 https://pypi.org/project/python-jsonrpc/

和NPM 不一样 他没有global选项 他安装的就是全局的安装的类库叫python-jsonrpc

但是在代码用的叫pyjsonrpc 这个要注意

但是呢?

报错

 这是因为镜像的问题换一个

https://www.v2ex.com/t/200840

重装一下

 成功!

简单写一个 验证是否工作 就是2个数相加 看返回的和对不对

""" Backend service """

import pyjsonrpc

SERVER_HOST = 'localhost'
SERVER_PORT = 4040


class RequestHandler(pyjsonrpc.HttpRequestHandler):
    """ RPC request handler """
    @pyjsonrpc.rpcmethod
    def add(self, num1, num2):  # pylint: disable=no-self-use
        """ Test method """
        print "add is called with %d and %d" % (num1, num2)
        return num1 + num2


# Threading HTTP Server
HTTP_SERVER = pyjsonrpc.ThreadingHttpServer(
    server_address=(SERVER_HOST, SERVER_PORT),
    RequestHandlerClass=RequestHandler
)

print "Starting HTTP server on %s:%d" % (SERVER_HOST, SERVER_PORT)

HTTP_SERVER.serve_forever()
service.py

 

说明至少没有语法错误

原文地址:https://www.cnblogs.com/PoeticalJustice/p/9568377.html