Comments (9)
Nevermind, no more than 30 seconds after submitting this I realized that pyramid_rpc is taking the arguments a step further than I expected.
For example, if the request is:
{"jsonrpc":"2.0","method":"service_render","id":1,"params":{"test":"1","test2":"2"}}
then the method signature will need to be:
@jsonrpc_method(endpoint='api')
def service_render(request, data, data2):
and then pyramid_rpc will map "1" to data and "2" to data2.
This works, but is slightly unintuitive. I will propose some additional documentation around this.
Thank you and hopefully this issue will help someone else in the future.
from pyramid_rpc.
I am making a mess of this issue now, but it still appears to not be working correctly. Even with my understanding from my comment above, the values for data and data2 are not the values of the named parameters but rather the name.
As I said the values were "1" and "2" for data and data2 respectively. This is not happening, the values for data and data2 are actually "test" and "test2"
Sorry for the confusion but I think I have identified the problem. Hopefully we can find a solution.
from pyramid_rpc.
Ok, last post I promise :-)
So it turns out pyramid_rpc is SUPER smart.
It maps the named parameters to their associated parameter names... Meaning in order to call:
def service_render(request, data, data2):
the params should be:
{"jsonrpc":"2.0","method":"service_render","id":1,"params":{"data":"1","data2":"2"}}
Then the values are correct inside the method.
Sorry for the mess.
from pyramid_rpc.
Named parameters are not supported with pyramid_rpc right now. The fact that its working for you is lucky because the params
dict is unordered.
I haven't seen a compelling reason to support named parameters. In all of the servers I've looked at while implementing JSON-RPC I have never seen one that supported it. If you know of one that does, let me know and I'll think about it. Same goes for clients. XML-RPC doesn't support them and gets along just fine because in reality it is RPC where you are calling a function with a defined signature, so it's on you (the client) to provide the arguments to match the signature in the correct order.
from pyramid_rpc.
thank you for the follow up mmerickel.
Named parameters isn't that important to me. I think the only reason I ventured down that path was because I was getting inconsistent or unintended data being passed to my json-rpc exposed functions.
As I was saying before, I was getting the name of the parameters and not the values.
I would propose changing line 126 in jsonrpc.py from:
request.rpc_args = tuple(body.get('params', []))
to
request.rpc_args = tuple(body.get('params', []).values())
I very well may not understand the full repercussions of this change, but in my anecdotal scenario it fixed my issues.
from pyramid_rpc.
I will think about adding support for named parameters, but like I said: it's not supported right now. Thus, you should not be sending a dictionary as the params argument.
from pyramid_rpc.
I spent about one hour today to figure out, why my named parameters sent by a java-jsonrpc-client do not make it to my rpc_method in pyramid. Actually i came here to have a look at the code, but then found this Issue here first.
Since named parameters are supported in the spec proposal ( http://en.wikipedia.org/wiki/JSON-RPC#Version_2.0_.28Specification_Proposal.29 ) I would love to see them supported by pyramid_rpc.
from pyramid_rpc.
implemented in pull request #17
from pyramid_rpc.
The trunk now supports named parameters. This will be in the next release.
from pyramid_rpc.
Related Issues (20)
- JSON-RPC may be broken on Pyramid 1.1 HOT 1
- Tests don't pass under 2.4 HOT 1
- JSON-RPC methods should be able to be invoked using HTTP GET HOT 4
- DeprecationWarning get always displayed when using python2.6 HOT 3
- AMF support broken? HOT 5
- Need to distinguish Forbidden from RequestInvalid in jsonrpc HOT 2
- JsonRpcError: data argument never used HOT 1
- Allow custom JSONEncoder subclasses for JSON-RPC endpoints HOT 3
- config.scan not found @xmlrpc_method HOT 15
- decide how to handle json-rpc responses
- Encoding error HOT 1
- Support json rpc 2.0 batch HOT 3
- Allow us to disable exception views HOT 2
- JSON-RPC traversal HOT 6
- remove the route predicate and add a pattern for security HOT 5
- MethodPredicate throws AttributeError when tested against batched requests HOT 1
- Cannot handle *args, **kwargs decorators
- MessagePack support HOT 2
- install error HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pyramid_rpc.