Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

params passed as an array while a json object is expected #27

Open
snitko opened this issue Aug 21, 2014 · 1 comment
Open

params passed as an array while a json object is expected #27

snitko opened this issue Aug 21, 2014 · 1 comment

Comments

@snitko
Copy link

snitko commented Aug 21, 2014

So, I've been playing with a Counterparty json-rpc server (for reference, don't look too hard at it: http://counterpartyd.readthedocs.org/en/latest/API.html) and it returned me an error everytime I tried to make a request with params saying the following:

{ "message": "Invalid Request", "data": "Arguments must be passed as a JSON object (list of unnamed arguments not supported)" }

I digged deeper into your code and found the issue here:

module Jimson
  class ClientHelper

    def send_single_request(method, args)
      namespaced_method = @namespace.nil? ? method : "#@namespace#{method}"
      post_data = MultiJson.encode({
        'jsonrpc' => JSON_RPC_VERSION,
        'method'  => namespaced_method,
        'params'  => args.try(:first), # <= PROBLEM WAS HERE: it was just `args`
        'id'      => self.class.make_id
      })
      resp = RestClient.post(@url, post_data, @opts)
      if resp.nil? || resp.body.nil? || resp.body.empty?
        raise Client::Error::InvalidResponse.new
      end

      return resp.body
    end

  end

end

So it seems the server I'm interacting with expects params to be a json object and not an array. The fix I applied - using the first element of the array - works, however I'm not sure whether this is something specific to the Counterparty RPC server or maybe it's jimson implementation deficiency. Please take a look at it, you might want to decide to give users more freedom as to how to pass params.

@sts
Copy link

sts commented May 11, 2016

Same issue here. According to http://www.jsonrpc.org/specification#parameter_structures the request object needs to hold parameters in a object, with { parameter_name => value } or as an array in the order the server expects the keys to be.

4.2 Parameter Structures
If present, parameters for the rpc call MUST be provided as a Structured value. Either by-position through an Array or by-name through an Object.

  • by-position: params MUST be an Array, containing the values in the Server expected order.
  • by-name: params MUST be an Object, with member names that match the Server expected parameter names. The absence of expected names MAY result in an error being generated. The names MUST match exactly, including case, to the method's expected parameters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants