Thrift:Python服务器,Erlang客户端错误。。。{thrift_套接字服务器,244,{child_error,function_子句,[]}}

2024-10-03 15:34:11 发布

您现在位置:Python中文网/ 问答频道 /正文

这实际上是我关于stackoverflow的第一个问题,但我一直有一个问题,我似乎真的无法解决。我正在制作一个Python服务器,它通过thrift调用erlang客户机。我在thrift中创建的惟一函数是bar,它接受一个整数并打印bar(integer)。这里是Python客户端,它并不太复杂:

#!/usr/bin/env python

import sys
sys.path.append('../gen-py')

from foo import Foo
from foo.ttypes import *
from foo.constants import *

from thrift import Thrift
from thrift.transport import TSocket
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol

try:
   # Make socket
   transport = TSocket.TSocket('localhost', 9999)

   # Buffering is critical. Raw sockets are very slow
   transport = TTransport.TBufferedTransport(transport)

   # Wrap in a protocol
   protocol = TBinaryProtocol.TBinaryProtocol(transport)

   # Create a client to use the protocol encoder
   client = Foo.Client(protocol)

   # Connect!
   transport.open()

   msg = client.bar(1452)
   print msg

   transport.close()

except Thrift.TException, tx:
   print "%s" % (tx.message)

这是我的thrift客户端,它正在监听9999端口:

^{pr2}$

所以我启动thrift客户机,从python服务器调用客户端.bar(1452),不幸地得到一个子错误:

=CRASH REPORT==== 5-Jul-2013::08:34:32 ===
  crasher:
    initial call: thrift_socket_server:acceptor_loop/1
    pid: <0.51.0>
    registered_name: []
    exception error: no function clause matching 
                     thrift_socket_transport:read({data,#Port<0.1067>,3600000},
                                                  -2147418111) (src/thrift_socket_transport.erl, line 53)
      in function  thrift_transport:read/2 (src/thrift_transport.erl, line 67)
      in call from thrift_framed_transport:read/2 (src/thrift_framed_transport.erl, line 79)
      in call from thrift_transport:read/2 (src/thrift_transport.erl, line 67)
      in call from thrift_binary_protocol:read_data/2 (src/thrift_binary_protocol.erl, line 315)
      in call from thrift_binary_protocol:read/2 (src/thrift_binary_protocol.erl, line 286)
      in call from thrift_binary_protocol:read/2 (src/thrift_binary_protocol.erl, line 175)
      in call from thrift_protocol:read_specific/2 (src/thrift_protocol.erl, line 186)
    ancestors: [foo_service,foo_sup,<0.46.0>]
    messages: []
    links: [<0.48.0>,#Port<0.1067>]
    dictionary: []
    trap_exit: false
    status: running
    heap_size: 987
    stack_size: 27
    reductions: 513
  neighbours:

=ERROR REPORT==== 5-Jul-2013::08:34:32 ===
{thrift_socket_server,244,{child_error,function_clause,[]}}

有什么想法吗?谢谢你的帮助!在


Tags: infromimportsrcreadfoolinebar
1条回答
网友
1楼 · 发布于 2024-10-03 15:34:11

明白了!当我在erlang文件中指定framedtransport时,我正在使用TBufferedTransport。我把它改成了TFramedTrasport,重新编译了我的thrift文件,一切都很顺利。在

相关问题 更多 >