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

Issue in Python3.3 and not in Python2.7 #82

Closed
brechmos opened this issue Jun 7, 2015 · 3 comments
Closed

Issue in Python3.3 and not in Python2.7 #82

brechmos opened this issue Jun 7, 2015 · 3 comments

Comments

@brechmos
Copy link

brechmos commented Jun 7, 2015

First, thank you so for writing this package! I appreciate your work and it has been very helpful.

I have a simple socket.io emitter and listener I wrote that has been running for the past 6 months ago or so. I upgraded python from 2.7 to 3.3 and am now getting an odd error. The pared down code is as follows:

Python socketio-client emitter is:

    from socketIO_client import SocketIO, LoggingNamespace

    rapidssl = '<dir>/GT_RapidSSL_SHA-2_under_SHA-1_root_bundle.crt'
    with SocketIO('https://<url>', 41777, LoggingNamespace, verify=rapidssl) as socketIO:
        socketIO.emit('test', {'param1': '1', 'param2': 2})
        socketIO.wait(seconds=1)
        socketIO.disconnect()

Node socket.io  listener:

    var http = require('https')
    var fs = require('fs')

    var options = {
      key: fs.readFileSync('key.pem'),
      cert: fs.readFileSync('cert.pem')
    };


    // Send index.html to all requests
    var server = http.createServer(options, function(req, res) {
        res.writeHead(200, {'Content-Type': 'text/html'});
        res.end('here' );

    });

    // Socket.io server listens to our server
    var io = require('socket.io').listen(server);

    // Emit welcome message on connection
    io.sockets.on('connection', function(socket) {
        process.stdout.write('=-----------------------------------------------\n');
        process.stdout.write('Got a connection\n');
        console.log(socket.name + ' ' + socket.id + ' ' + socket.handshake.headers.origin + ' ' + socket.handshake.address + ' ' + socket.handshake.headers);
        console.log( socket.handshake.headers );

        socket.on("test", function(msg) {
            var obj = eval(msg);
            process.stdout.write('Got a test for ' + obj.param1 + ' ' + obj.param2 + '\n');
        });


    });

    io.sockets.on('disconnect', function(socket) {
        process.stdout.write('Disconnected!!\n');
    });

    server.listen(41777);

When I run the first script with with Python2.7 everything works fine. No errors and I get the proper output from the socket.on("test"...) part.

When I run the code with Python3.3 then I get errors:

    socketIO_client.exceptions.ConnectionError: unexpected status code (400 {"code":1,"message":"Session ID unknown"})

The line in the socketIO-client python code is looking for a response of 200:

    if 200 != status_code:
        raise ConnectionError('unexpected status code (%s %s)' % (
            status_code, response.text))
    return response

It appears others have asked similar questions but I have not seen any responses that work. I have tried different machines, Python 3.3 and Python 3.4 and tried re-installing the node and socket.io via npm but to no avail. The really weird thing is that 1 in 10 times I run it in Python 3.3 it works. The other 9/10 times I get the above error.

Any ideas would be appreciated.

@brechmos brechmos closed this as completed Jun 8, 2015
@brechmos
Copy link
Author

brechmos commented Jun 8, 2015

I realized I have a wrong issue here. I will repost the proper question.

@brechmos brechmos reopened this Jun 8, 2015
@brechmos brechmos closed this as completed Jun 8, 2015
@invisibleroads
Copy link
Owner

What happens when you set verify=False?

with SocketIO('https://<url>', 41777, LoggingNamespace, verify=False) as socketIO:
    pass

Support for SSL certificate verification is experimental and even though the code is there, I recall having trouble getting it to work.

Connecting to an HTTPS/WSS server is only guaranteed with verify=False.

@invisibleroads
Copy link
Owner

Server certificate verification and client certificate encryption seem to work properly now (see #54). I haven't changed anything in the code, so I am assuming that there must have been a fix introduced in the requests library. Please check whether pip install -U requests fixes your issue.

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