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

Python 3 + uwsgi RPC slighty broken #959

Open
squeaky-pl opened this issue Jul 9, 2015 · 2 comments
Open

Python 3 + uwsgi RPC slighty broken #959

squeaky-pl opened this issue Jul 9, 2015 · 2 comments

Comments

@squeaky-pl
Copy link

There is a small problem with Python 3 and uwsgi RPC, all the functions expect bytestrings (including the names used to identify them) but uwsgi.register_rpc expects unicode since it uses s which means Unicode on Python 3.

--- a/plugins/python/uwsgi_pymodule.c
+++ b/plugins/python/uwsgi_pymodule.c
@@ -428,7 +428,7 @@ PyObject *py_uwsgi_register_rpc(PyObject * self, PyObject * args) {
        char *name;
        PyObject *func;

-       if (!PyArg_ParseTuple(args, "sO|B:register_rpc", &name, &func, &argc)) {
+       if (!PyArg_ParseTuple(args, "yO|B:register_rpc", &name, &func, &argc)) {
                return NULL;
        }

Now you can run this example without type errors:

import uwsgi

def hello_world(person):
    return 'Hello {}'.format(person).encode('utf-8')

print(uwsgi.register_rpc(b"hello", hello_world))


print(uwsgi.rpc(None, b"hello", b"Katy"))
print(uwsgi.call(b"hello", b"Jenny"))


def application(environ, start_response):
    start_response('200 OK', [('Content-Type', 'text/plain')])

    print(uwsgi.rpc(None, b"hello", b"world"))
    print(uwsgi.call(b"hello", b"Sam"))

    return [b'Hello']
@squeaky-pl squeaky-pl changed the title Python 3 + uwsgi RPC broken Python 3 + uwsgi RPC slighty broken Jul 9, 2015
@squeaky-pl
Copy link
Author

Also the docs would benefit from using b prefix in the RPC examples

@unbit
Copy link
Owner

unbit commented Jul 9, 2015

You can use

#ifdef PYTHREE
...
#else
...
#endif

to distinguished between the two cases (its ok to accept it as a pull request)

If you make a pull request for uwsgi-docs i will accept it too for sure. Thanks a lot

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

No branches or pull requests

3 participants