python中的JsonRpc客户端

时间:2014-10-09 03:06:34

标签: python json ubuntu stanford-nlp json-rpc

我正在尝试通过python使用StanfordParser,我正在使用它的this实现,它基本上是一个远程服务器,响应我理解的json请求。 他们在启动服务器

后为客户端推荐以下实施模板
import jsonrpc
from simplejson import loads
server = jsonrpc.ServerProxy(jsonrpc.JsonRpc20(), jsonrpc.TransportTcpIp(addr=("127.0.0.1", 8080)))

result = loads(server.parse("Hello world.  It is so beautiful"))
print "Result", result

但是我没有使用jsonrpc的经验,我只是使用pip install json-rpc安装它。这似乎没有奏效,因为当我尝试运行示例客户端时,我得到以下异常。

Traceback (most recent call last):
  File "/root/PycharmProjects/testingStanfordParser/parser.py", line 1, in <module>
    import jsonrpc
  File "/usr/local/lib/python2.7/dist-packages/jsonrpc/__init__.py", line 6, in <module>
    from .manager import JSONRPCResponseManager
  File "/usr/local/lib/python2.7/dist-packages/jsonrpc/manager.py", line 12, in <module>
    from .jsonrpc1 import JSONRPC10Response
  File "/usr/local/lib/python2.7/dist-packages/jsonrpc/jsonrpc1.py", line 3, in <module>
    from .base import JSONRPCBaseRequest, JSONRPCBaseResponse
  File "/usr/local/lib/python2.7/dist-packages/jsonrpc/base.py", line 1, in <module>
    from .utils import JSONSerializable
  File "/usr/local/lib/python2.7/dist-packages/jsonrpc/utils.py", line 31, in <module>
    class DatetimeDecimalEncoder(json.JSONEncoder):
AttributeError: 'module' object has no attribute 'JSONEncoder'

1 个答案:

答案 0 :(得分:3)

如前所述,他们有自己的jsonrpc.py实现。 它可以从以下链接下载。

https://github.com/dasmith/stanford-corenlp-python/blob/master/jsonrpc.py