Connect to socket.io server using https
Thank you for creating this socket.io python library.
Previously, I have a JavaScript socket.io client application as follow
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.0.4/socket.io.js"></script>
<script>
console.log("start");
var socket = io('https://ws-api.iextrading.com/1.0/tops');
// Listen to the channel's messages
socket.on('message', message => console.log(message));
// Connect to the channel
socket.on('connect', () => {
console.log("connect");
// Subscribe to topics (i.e. appl,fb,aig+)
socket.emit('subscribe', 'snap,fb,aig+');
// Unsubscribe from topics (i.e. aig+)
socket.emit('unsubscribe', 'aig+');
});
// Disconnect from the channel
socket.on('disconnect', () => console.log('Disconnected.'));
</script>
Just save it as HTML, and open with chrome. I can get
start connect
Now, I want to port the client application running in python environment
from socketIO_client import SocketIO, LoggingNamespace
import logging
logging.getLogger('socketIO-client').setLevel(logging.DEBUG)
logging.basicConfig()
def on_message():
print('message')
def on_connect():
print('connect')
def on_disconnect():
print('disconnect')
print("debug 0")
socketIO = SocketIO(host='https://ws-api.iextrading.com/1.0/tops', verify=False)
print("debug 1")
socketIO.on('message', on_message)
print("debug 2")
socketIO.on('connect', on_connect)
print("debug 3")
socketIO.on('disconnect', on_disconnect)
print("debug 4")
The code stucks at socketIO = SocketIO(.... What I get is
debug 0 C:\yocto\sandbox\venv\lib\site-packages\urllib3\connectionpool.py:858: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings InsecureRequestWarning) WARNING:socketIO-client:ws-api.iextrading.com:443/1.0/tops/socket.io [engine.io waiting for connection] unexpected status code (404 Not Found) C:\yocto\sandbox\venv\lib\site-packages\urllib3\connectionpool.py:858: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings InsecureRequestWarning) C:\yocto\sandbox\venv\lib\site-packages\urllib3\connectionpool.py:858: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings InsecureRequestWarning)
May I know what I can do to get this fixed? As, my Javascript client code works OK with server. Hence, by dealing with same server, I expect Python socketIO-client works as well.
Thanks
Have met with same issue. Figured out the cause.
First the /1.0/tops is a namespace instead of a path. So please use the code below. Secondly, the root cause is IEX for now is using socket.io v2, thus you might want to use the socketio-client-nexus pip which support v2.
class TopsNamespace(BaseNamespace):
def on_message(self, *args):
print('on_response', args)
def on_connect(self):
logging.info('connected')
def on_disconnect(self):
logging.info('disconnect')
logging.info('Conneting to IEX')
socketIO = SocketIO(host='https://ws-api.iextrading.com')
tops = socketIO.define(TopsNamespace, '/1.0/tops')