Python socket io client does'n accept connection but node client does

Question:

There is a node sever and I want to perform a socket connection with my client.
I can connect with node but python version doesn’t connect.

what is wrong with python version?

const io = require('socket.io-client');


const socket = io("wss://winseller.turkmenexpress.ir", {
  auth: {
    token: "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJwSWQiOiIyNyIsIm1vYmlsZSI6IjA5MTI3Mzk2Nzk0In0.moQMWb_I1CyhCJ9Gh4TLH8LiVwtE7h2wH4DPY-KEeT0"
  }
});

socket.on('disconnect', function(data){
  console.log('server is down');
})

socket.on('connect', function(data){
  console.log('socket is connected');
})
import socketio

sio = socketio.Client()
sio.connect('wss://winseller.turkmenexpress.ir',auth={
    'token': "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJwSWQiOiIyNyIsIm1vYmlsZSI6IjA5MTI3Mzk2Nzk0In0.moQMWb_I1CyhCJ9Gh4TLH8LiVwtE7h2wH4DPY-KEeT0"
  },wait=True, wait_timeout= 10
)


@sio.on('connect')
def connect():
  print('socket is connected')

@sio.on('disconnect')
def disconnect():
  print('server is down')
Asked By: Siavash Moghadas

||

Answers:

first reinstall your packages and then try to use socketio in this way:

sio = socketio.Client()

@sio.event
def connect():
    print('socket connected')

@sio.event
def my_message(data):
    print('message received with ', data)
    sio.emit('my response', {'response': 'my response'})

@sio.event
def disconnect():
    print('socket disconnected from server')

sio.connect('wss://winseller.turkmenexpress.ir', auth={
    'token': "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJwSWQiOiIyNyIsIm1vYmlsZSI6IjA5MTI3Mzk2Nzk0In0.moQMWb_I1CyhCJ9Gh4TLH8LiVwtE7h2wH4DPY-KEeT0"
  })
sio.wait()
Answered By: User12

I change the code a bit just to check if this is working and seems fine.

import socketio
print('start...')

sio = socketio.Client()
sio.connect('wss://winseller.turkmenexpress.ir',auth={
    'token': "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJwSWQiOiIyNyIsIm1vYmlsZSI6IjA5MTI3Mzk2Nzk0In0.moQMWb_I1CyhCJ9Gh4TLH8LiVwtE7h2wH4DPY-KEeT0"
  },wait=True, wait_timeout= 10
)

print('phase 1 ...', sio)

@sio.on('connect')
def connect():
  print('socket is connected')

@sio.on('disconnect')
def disconnect():
  print('server is down')


connect()

this is the result:

start...
phase 1 ... <socketio.client.Client object at 0x000001EC7FB96020>
socket is connected

So aside from the result what were you expecting ?

Answered By: D.L
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.