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

BadNamespaceError / is not a connected namespace #1113

Closed
nouser000 opened this issue Jan 3, 2023 · 4 comments
Closed

BadNamespaceError / is not a connected namespace #1113

nouser000 opened this issue Jan 3, 2023 · 4 comments
Labels

Comments

@nouser000
Copy link

Describe the bug
Sometimes it comes back to me

File "/usr/local/lib/python3.10/dist-packages/socketio/client.py", line 393, in emit   
socketio.exceptions.BadNamespaceError / is not a connected namespace

To Reproduce
I've been trying various ways

First attempt:

sio = socketio.Client(logger=False,ssl_verify=False,reconnection=True)
sio.connect('https://domain:3001' ,transports="polling")
sio.emit('debug', {'room': 'hi','msg':'Hi mate'}) #works
sio.sleep(5)
sio.emit('debug', {'room': 'hi','msg':'Hi again'}) #works again

... other tasks ...

sio.emit('debug', {'room': 'hi','msg':'Tasks finish'}) #error

Second attempt:

sio = socketio.Client(logger=False,ssl_verify=False,reconnection=True)
sio.connect('https://domain:3001' ,transports="polling")
sio.emit('debug', {'room': 'hi','msg':'Hi mate'}) #works
sio.sleep(5)
sio.start_background_task(task(),123) #task() solves multiple tasks
sio.wait()

Expected behavior
Send message at the end of a long task

Logs

Sending packet MESSAGE data 2["debug",{"room":"hi","msg":"Hi again"}]
Received packet PING data 
Sending packet PONG data 
Sending polling GET request to https://domain:3001/socket.io/?transport=polling&EIO=4&sid=m_JKfkEHmf3Apu_8AAAU
Received packet CLOSE data 
Sending packet CLOSE data None
disconnected from server
Waiting for write loop task to end
Unexpected status code 400 in server response, aborting
Exiting write loop task
Exiting read loop task
@miguelgrinberg
Copy link
Owner

miguelgrinberg commented Jan 3, 2023

The emit that fails is being issued after the server disconnected you. You are reporting the bug as being that, but in reality you need to find out why is the server disconnecting after a while. Your client code could also be more robust and detect the disconnection to prevent issuing emits while disconnected.

@nouser000
Copy link
Author

La emisión que falla se emite después de que el servidor lo desconectó. Está informando que el error es eso, pero en realidad necesita averiguar por qué el servidor se desconecta después de un tiempo. Su código de cliente también podría ser más robusto y detectar la desconexión para evitar emitir emisiones mientras está desconectado.

My server code is

const fs = require('fs');
const { createServer } = require("https");
const { Server } = require("socket.io");

const httpServer = createServer({
    key: fs.readFileSync("/priv.key"),
    cert: fs.readFileSync("/cert.crt")
});


const options = {
   cors: {
        origin: "*"
    },always_connect:true
};

const io = new Server(httpServer, options);
io.on("connection", function (socket) {
    socket.on("debug", function (data) {
        console.log("RECEIVE: "+data.msg);
    });
});

 
httpServer.listen(3001, function () {
    console.log("StARTED ");
});

It's just that, I wouldn't see why it disconnects me

@nouser000
Copy link
Author

other times response is:
Unexpected status code 400 in server response, aborting

Log:

Received packet CLOSE data 
Sending packet CLOSE data None
Waiting for write loop task to end
Unexpected status code 400 in server response, aborting
Exiting write loop task
Exiting read loop task

@miguelgrinberg
Copy link
Owner

I really cannot tell you why, but as you can see in your own logs, the server is responding with a 400 error. Why is your Node server doing this?

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

No branches or pull requests

2 participants