drgovyk64676 2014-10-05 07:13
浏览 67
已采纳

从python JSON服务器和PHP客户端获取“error”=>“Array”数组响应

I've written a simple JSON RPC server in python as an interface to a python program. The server works fine when I use curl to to manually construct JSON requests from it. When I use the JSON library from here: http://jsonrpcphp.org/ I just get an error response "Array" in return.

I'm not exactly sure what I'm doing wrong, because I've tested the server and it works when I don't use the PHP library.

I've check and the content type is set to "application/json".

Heres the PHP code:

$server= new jsonRPCClient("http://$serveraddress:$port");


try {
    echo($server->do_stop());
} catch (Exception $e) {
    echo "caught exception: ", $e->getMessage() ,"<br />";
}

EDIT:

Here's a print_r of the $server object (localhost should have http:// before it but I can't Put it in):

jsonRPCClient Object ( [debug:jsonRPCClient:private] => [url:jsonRPCClient:private] => localhost:3000[id:jsonRPCClient:private] => 1 [notification:jsonRPCClient:private] => [proxy] => ) 

do_stop() just raises an exception "Request Error: Array"

EDIT2: Solved the rpoblem, turns out that I was requesting an incorrect method. I forgot that I changed the name to stop().

Logic errors...

  • 写回答

1条回答 默认 最新

  • dtwzwmv87399 2014-10-05 08:09
    关注

    construct ur object setting the debug flag to true

     $server= new jsonRPCClient("http://$serveraddress:$port", true);
    

    reading the source code of the json rpc client, seems like the error is coming from ur server:

        // final checks and return
        if (!$this->notification) {
            // check
            if ($response['id'] != $currentId) {
                throw new Exception('Incorrect response id (request id: '.$currentId.', response id: '.$response['id'].')');
            }
            if (!is_null($response['error'])) {
                throw new Exception('Request error: '.$response['error']);
            }
    
            return $response['result'];
    
        } else {
            return true;
        }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?