Git Product home page Git Product logo

pyramid_rpc's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pyramid_rpc's Issues

AMF support broken?

hi,

I was starting to play around with pyramid_rpc and amf, but even the most basic server does not work.

RemotingError: Incorrect MIME type received. (got: text/html; charset=UTF-8)

my main function contains:

    config.add_route('amf', '/amf')
    config.add_view('status_basic.amfgateway.AmfGateway', route_name='amf',
                   permission=NO_PERMISSION_REQUIRED)

The view function bound to the service is

def amftest(request):
    return 'hello'

accessing http://127.0.0.1:6543/amf with firefox works as expected (it throws an error 'cause it's a GET request)

then I wrote a mall script as shown on the django pyamf page to test the amf service that reads as follows:

import logging
from pyamf.remoting.client import RemotingService

logging.basicConfig(
    level=logging.DEBUG,
    format='%(asctime)s %(levelname)-5.5s [%(name)s] %(message)s'
)

url='http://127.0.0.1:6543/amf'
gw = RemotingService(url)
service = gw.getService('example')
service.test()

I've tried with request_method="POST", accept='application/x-amf' added to add_route, add_view, but neither worked.

The traceback received is: RemotingError: Incorrect MIME type received. (got: text/html; charset=UTF-8)

Checking the server logs, seemingly no activity reaches the server. Any ideas?

install error

OS: Windows7
Python 2.6.6
Buildout 1.5.2
Distribute 0.6.10

Getting distribution for 'pyramid-rpc'.
error: c:\users\aodag\appdata\local\temp\easy_install-4tuksn\pyramid_rpc-0.1\CHANGES.txt: No such file or directory
An error occurred when trying to install pyramid-rpc 0.1. Look above this message for any errors that were output by eas
y_install.

decide how to handle json-rpc responses

Rationalize in my head why I chose to have notifications return a "204 No Content" but everything else, including errors, returns "200 OK".

I think notifications should probably return a 200 with a null body, instead of the current behavior.

There was a notion of supporting the draft "JSON-RPC over HTTP" specification but it still feels very much like a draft to me.

JsonRpcError: data argument never used

this statement

raise JsonRpcParamsInvalid(data=dict(email='must contain a @'))

will return a value identical to this one

raise JsonRpcParamsInvalid()

because 'data' is not converted in JsonRpcError.as_dict()

I suggest to add these 2 lines to JsonRpcError.as_dict()

def as_dict(self):
    """Return a dictionary representation of this object for
    serialization in a JSON-RPC response."""
    error = dict(code=self.code,
                 message=self.message)
  •   if self.data:
    
  •       error['data']=self.data
    return error
    

JSON-RPC 2.0 Specification proposal don't say nothing about the 'data' except it can be omitted and the value must be defined by the "Server"

Allow us to disable exception views

We use pyramid_rpc at my company and we have some unique exception handling requirements (basically to help us match up exceptions on the client and server side). I wanted to register an exception view for Exception, but I couldn't because add_jsonrpc_endpoint already does that.

(I worked around the issue by registering an exception view for StandardError, which is a superclass of nearly all Python--provided exceptions (and we already have a base class for our service's exceptions), but it would be nice to be able to tell add_jsonrpc_endpoint to skip the exception view.)

Need to distinguish Forbidden from RequestInvalid in jsonrpc

I want to have my pyjamas (json-rpc) client display a login dialog as a response to Forbidden.

Currently (git head), Forbidden is returned as JsonRpcRequestInvalid.

Invalid Request is defined in the JSON-RPC 2.0 spec http://jsonrpc.org/spec.html :
The JSON sent is not a valid Request object.

Forbidden needs to be distinguished from Invalid Request.

I believe that, since the JSON-RPC spec requires a json-rpc response, the proper response would be a jsonrpc_error_response with an error code of 401, with message "Unauthorized".

  • Jim Washington

Encoding error

I use Python 2.7 and try these two codes with the last version of pyramid_rpc:

  • server.py:

from wsgiref.simple_server import make_server
from pyramid.config import Configurator
from pyramid_rpc.xmlrpc import xmlrpc_method

def say_hello(request, name):
return 'Hello, %s' % name

if name == 'main':
config = Configurator()
config.include('pyramid_rpc.xmlrpc')
config.add_xmlrpc_endpoint('xmlrpc', '/xmlrpc')
config.add_xmlrpc_method(say_hello, endpoint='xmlrpc', method='say_hello')

app = config.make_wsgi_app()
server = make_server('0.0.0.0', 6543, app)
server.serve_forever()
  • call.py:

-- coding: utf-8 --

import xmlrpclib

proxy = xmlrpclib.ServerProxy('http://localhost:6543/xmlrpc')
print proxy.say_hello(u'Sébastien')

And, it raises an exception: xmlrpclib.Fault: <Fault -32500: 'application error'>.

If I change line 79 of xmlrpc.py from:

response.body = (
    xmlrpclib.dumps(
        (result,), methodresponse=True
    ).encode(response.charset)

to:

response.body = (
    xmlrpclib.dumps(
        (result,), methodresponse=True
    )

it works perfectly.

I have tried the new code on more complex calls and it always works.

request.xmlrpc_args['name'] results in TypeError: tuple indices must be integers, not str

The say_hello function in the documentation contains a reference to request.xmlrpc_args['name']. From what I can tell that should be request.xmlrpc_args[0].

Using that results in

 File "rpc.wsgi", line 8, in say_hello
    return 'Hello, %s' % request.xmlrpc_args['name']
TypeError: tuple indices must be integers, not str

Here is my complete script

 from pyramid_rpc import xmlrpc_view
 from pyramid.config import Configurator
 from paste.httpserver import serve

 @xmlrpc_view()
 def say_hello(request):
     return 'Hello, %s' % request.xmlrpc_args['name']

 config = Configurator()
 config.add_route('RPC2', '/api/xmlrpc', view='pyramid_rpc.xmlrpc_endpoint')
 config.scan()
 application = config.make_wsgi_app()

 if __name__ == '__main__':
     serve(application, host='0.0.0.0:5000')

Cannot handle *args, **kwargs decorators

When attempting to wrap the view functions in a normal Python decorator (e.g. not a pyramid style decorator) that utilizes the *args, **kwargs pattern, pyramid_rpc breaks due to the inability to determine the number of arguments. This is true even if the decorator is using functools.wraps, which on Python 3 is smart enough to keep the function signature the same.

From digging into this, it appears this is because pyramid_rpc pokes at the code object directly instead of using a smarter helper function.

The context for this is wanting to use the @typechecked decorator from typeguard so that parameters passed from the client are type checked and generate an XMLRPC level error, instead of raising an unhandled exception (which typically get logged into something like Sentry).

However, attempting to use that results in an exception: ViewMapperArgsInvalid('too many arguments').

config.scan not found @xmlrpc_method

I try to install pyramid 1.3.2 in new environment. When i ran old application I got
xmlrpclib.Fault: <Fault -32601: 'server error; requested method not found'>
My application use pyramid_rpc with @xmlrpc_method to config endpoint. I try to change @xmlrpc_method to config.add_xmlrpc_method, it work. I am not sure It is my mistake or pyramid 1.3.2 not support @xmlrpc_method

Issue with named parameters in the request.params

Hello,

I believe there is a bug with how pyramid_rpc handles named parameters for a json-rpc calls. The 2.0 spec seems to indicate that it should be supported:

http://en.wikipedia.org/wiki/JSON-RPC#Version_2.0_.28Specification_Proposal.29

My POST request (from javascript) has the data:

{"jsonrpc":"2.0","method":"service_render","id":1,"params":{"test":"1"}}

The issue is that it seems the params is being cast to a tuple which causes it to loose its key/value association. I am still somewhat new to python so I wasn't able to pin point the correct solution, but I did track down the line where the data is being lost: jsonrpc.py line 126.

I would expect that when the "data" is passed to my method as such:

@jsonrpc_method(endpoint='api')
def service_render(request, data):
......

that "data" has its key/values preserved.

Thanks for the great work, I will continue to look at it and try and find a solution.

install error

Moved from https://github.com/Pylons/pyramid/issues#issue/126 (appears to be problem of missing MANIFEST.in or using a Python that doesn't have setuptools-git installed to generate the tarball):

$ easy_install pyramid_rpc
Searching for pyramid-rpc
Reading http://pypi.python.org/simple/pyramid_rpc/
Reading http://pylonshq.com/
Best match: pyramid-rpc 0.1
Downloading http://pypi.python.org/packages/source/p/pyramid_rpc/pyramid_rpc-0.1.tar.gz#md5=0eb73e9fc32b4640fc65da8f333460df
Processing pyramid_rpc-0.1.tar.gz
Running pyramid_rpc-0.1/setup.py -q bdist_egg --dist-dir /tmp/easy_install-lawyiC/pyramid_rpc-0.1/egg-dist-tmp-NG2CO0
error: /tmp/easy_install-lawyiC/pyramid_rpc-0.1/CHANGES.txt: No such file or directory

remove the route predicate and add a pattern for security

I prefer to think of the parsing as a custom factory on the route that can setup the request after matching the route. We can then pass the request into a custom factory if the user specified one, and return the context. Imagine:

class AddUser(object):
    def __init__(self, request):
        pass

    def __acl__(self):
        return [
            (Allow, 'admin', 'create_users'),
        ]

def jsonrpc_factory(request):
    if request.method == 'addUser':
        return AddUser(request)

config.add_jsonrpc_endpoint('jsonrpc', '/jsonrpc', factory=jsonrpc_factory)

@jsonrpc_method(endpoint='jsonrpc', permission='create_users')
def addUser(request):
    # add a user

related: #31, #36

DeprecationWarning get always displayed when using python2.6

In one of my projects I was using pyramid_rpc 0.2 and updated it pyramid_rpc 0.3 and the new API. But I couldn't get rid of the DeprecationWarning even if I didn't have any old calls left. I even get the DeprecationWarning when trying "from pyramid_rpc.xmlrpc import xmlrpc_method" in a python2.6 shell. With python2.7 no DeprecationWarning gets display. This is because of the different behaviour about printing DeprecationWarning in Python 2.7 [1]. I don't know if this is a problem at all in pyramid_rpc but it confused me for some time as I was trying to figure out why I still got the DeprecationWarning displayed even if I couldn't find any old API calls.

$ python2.6
Python 2.6.6 (r266:84292, Dec 26 2010, 22:31:48)
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.

from pyramid_rpc.xmlrpc import xmlrpc_method
/usr/local/lib/python2.6/dist-packages/pyramid_rpc-0.3-py2.6.egg/pyramid_rpc/init.py:1: DeprecationWarning: xmlrpc_endpoint: Deprecated as of pyramid_rpc 0.3, use the new API as described in the documentation.
from pyramid_rpc.xmlrpc import xmlrpc_endpoint

$ python2.7
Python 2.7.1+ (r271:86832, Apr 11 2011, 18:13:53)
[GCC 4.5.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.

from pyramid_rpc.xmlrpc import xmlrpc_method

But when I enabled the display of DeprecationWarnings in python2.7, I get it there too:
$ python2.7 -Wd
Python 2.7.1+ (r271:86832, Apr 11 2011, 18:13:53)
[GCC 4.5.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.

from pyramid_rpc.xmlrpc import xmlrpc_method
/usr/local/lib/python2.7/dist-packages/pyramid_rpc-0.3-py2.7.egg/pyramid_rpc/init.py:1: DeprecationWarning: xmlrpc_endpoint: Deprecated as of pyramid_rpc 0.3, use the new API as described in the documentation.
from pyramid_rpc.xmlrpc import xmlrpc_endpoint

1: http://docs.python.org/dev/whatsnew/2.7.html#the-future-for-python-2-x

JSON-RPC traversal

Hi,
I'm trying to use pyramid_rpc package.
How can I use it, so that I can call a "JSON-RPC" method on a given object (providing an interface) accessed through ZODB traversal?

Thanks, for any help,
Thierry

Test Error with pyramid1.0b2

.../Users/odagiriatsushi/Envs/pyramid/lib/python2.6/site-packages/pyramid-1.0b2-py2.6.egg/pyramid/exceptions.py:15: DeprecationWarning: BaseException.message has been deprecated as of Python 2.6
self.message = message
/Users/odagiriatsushi/works/pyramid_rpc/pyramid_rpc/tests.py:143: DeprecationWarning: BaseException.message has been deprecated as of Python 2.6
self.assertEqual(response.message, "No method of that name was found.")
...E.

ERROR: test_call_function (pyramid_rpc.tests.TestXMLRPCViewDecorator)


Traceback (most recent call last):
File "/Users/odagiriatsushi/works/pyramid_rpc/pyramid_rpc/tests.py", line 79, in test_call_function
wrapped = decorator(foo)
File "/Users/odagiriatsushi/works/pyramid_rpc/pyramid_rpc/xmlrpc.py", line 68, in call
return view_config(route_name=self.route_name, name=method_name)(wrapped)
File "/Users/odagiriatsushi/Envs/pyramid/lib/python2.6/site-packages/pyramid-1.0b2-py2.6.egg/pyramid/view.py", line 414, in call
settings['_info'] = info.codeinfo
AttributeError: 'DummyVenusianInfo' object has no attribute 'codeinfo'


Ran 8 tests in 0.010s

FAILED (errors=1)

MethodPredicate throws AttributeError when tested against batched requests

It took a while, but in our app, we finally saw an instance where Pyramid tests a batched http request (as setup by parse_request_POST) against an api method's MethodPredicate, which raises an exception because the batched request doesn't have a rpc_method attribute.

Line 270 should be changed from
return getattr(request, 'rpc_method') == self.method
to
return hasattr(request, 'rpc_method') and getattr(request, 'rpc_method') == self.method

I'm not sure why it was not reproduced before now, or how to effectively test it.

Allow custom JSONEncoder subclasses for JSON-RPC endpoints

It would be great if it were possible to use subclasses of JSONEncoder for JSON-RPC endpoints. I'd like to be able to override the default function to customize the marshalling of my objects instead of having to put the code in to views.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.