2

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')
4
  • try ws://winseller.turkmenexpress.ir Commented Sep 7, 2022 at 11:35
  • @dean-van-greunen It doesn't work. Commented Sep 7, 2022 at 11:38
  • hi dadash. ws:// using for http ans wss:// using for tls orhttps://. Commented Sep 7, 2022 at 11:48
  • @User12 Hi brother, did you test that? all of parameter is real. I already test what you recommended. Commented Sep 7, 2022 at 11:53

2 Answers 2

2

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()
Sign up to request clarification or add additional context in comments.

5 Comments

thanks for response, I tried it but connection massage didn't shows up. I still get "socketio.exceptions.ConnectionError: One or more namespaces failed to connect".
first disable your authentication system and check using this connection: sio.connect('wss://winseller.turkmenexpress.ir', wait_timeout = 10). if this is ok, then try to authorized your client.
I don't access to server it's just an API to use.
ok. wait_timeout dont resolve your problem?
thanks bro, I reinstalled my packages and your code is working fine.
0

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 ?

4 Comments

So you connected right? maybe problem is with my side. it's part of my project. I am really appreciated with your help.
yes, the question is what are you expecting to see as a result ?
"socket is connected". I don't see that. and when i emit event it doesn't get it. node version is totally fine.
I reinstall socket package and your code worked with it. thank you so mush.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.