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

Encoding error #25

Closed
pppierre opened this issue Nov 21, 2012 · 1 comment
Closed

Encoding error #25

pppierre opened this issue Nov 21, 2012 · 1 comment

Comments

@pppierre
Copy link

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.

@mmerickel
Copy link
Member

Ok I managed to reproduce this

    def test_nonascii_request(self):
        def view(request, a, b):
            return {'a': a, 'b': b}
        config = self.config
        config.include('pyramid_rpc.xmlrpc')
        config.add_xmlrpc_endpoint('rpc', '/api/xmlrpc')
        config.add_xmlrpc_method(view, endpoint='rpc', method='dummy')
        app = config.make_wsgi_app()
        app = TestApp(app)
        val = 'S\xc3\xa9bastien'.decode('utf-8')
        resp = self._callFUT(app, 'dummy', (2, val))
        self.assertEqual(resp, {'a': 2, 'b': val})

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