2

I use Flask and Flask-SocketIO inside of a Python application.

Recently, when I start up the app, I am given this message:

The client is using an unsupported version of the Socket.IO or Engine.IO protocols (further occurrences of this error will be logged with level INFO)

From my searching, I come to this table in Flask-SocketIOs' docs, which suggests I have version incompatibilities in my system.

I would like to figure out which version of JavaScript Socket.IO I have. How can this be done?


System Details

If it's not obvious, I am new to JavaScript.

  • OS: macOS version 10.15.7
  • JavaScript version: 1.7
  • Browser: Google Chrome version 87.0.4280.88
  • Python version: 3.8.6
  • Packages from Python virtual environment:
Flask                                     1.1.2
Flask-SocketIO                            5.0.1
python-engineio                           4.0.0
python-socketio                           5.0.4
Intrastellar Explorer
  • 3,005
  • 9
  • 52
  • 119

4 Answers4

2

The conflict is probably from using different protocol revisions on the client and the server.

From socket.io Client API:

The protocol defines the format of the packets exchanged between the client and the server. Both the client and the server must use the same revision in order to understand each other.

To determine the revision number of the client,

From HTML:

<script src="<your-path-to>socket.io.js"></script>
<script>
  const socket = io('http://localhost');

  const revisionNumber = socket.protocol;
</script>

Or from JavaScript:

const io = require('socket.io-client');
// or with import syntax
import { io } from 'socket.io-client';

const revisionNumber = io.protocol;

Or from the Flask-SocketIO source code:

  1. search for __version__ in the file __init__.py. The line will look like this:
__version__ = '5.0.2dev'
  1. Using that __version__ value, look up the corresponding Socket.IO protocol revision:
+--------------+----------------+
| __version__  |  protocol rev. |
+--------------+----------------+
|    4.x.x     |     3, 4       |
+--------------+----------------+
|    5.x.x     |     5          |
+--------------+----------------+
terrymorse
  • 6,771
  • 1
  • 21
  • 27
  • 1
    Okay this will reveal how much of a noob I am. How can I figure out my path to `socket.io.js` for the HTML code block you posted? – Intrastellar Explorer Jan 08 '21 at 22:31
  • Thanks for updating the answer @terrymorse, I updated my question with details of my Python virtual environment. The version of `Flask-SocketIO` I have is `5.0.1`. However, I was interested in discerning my **JavaScript Socket.IO version**, since that's what I need to match Python with. You're correct, I am not loading from an HTML file. How can I get the JavaScript Socket IO version? – Intrastellar Explorer Jan 09 '21 at 02:41
  • I ran the JavaScript provided in this question after running `npm install socket.io-client`, and was output `5`. This still doesn't answer my question, I am looking for the JavaScript Socket.IO version, not a client version. I agree with the quote you have on matching versions, so I need to match the JavaScript Socket.IO version with my client's version. Also, thank you again for your pointers so far! :) – Intrastellar Explorer Jan 09 '21 at 02:49
  • I think the "server" in my case is Google Chrome, or is Google Chrome my client? I am using `Flask`, and now this is confusing me. All I know is I am getting that log message mentioning `unsupported version` when my versions of `Flask-SocketIO`, `python-engineio`, and `python-socketio` all seem to be compatible per the chart, so I was thinking I need to match my system with the version of JavaScript Socket.IO. Sorry for overcomplicating this answer @terrymorse and thank you for all your help – Intrastellar Explorer Jan 09 '21 at 21:33
  • @IntrastellarExplorer The socet.io client code runs in the browser, the server code runs on a server. See [Socket.IO docs](https://socket.io/docs/v3). Also see this github issue for [python-socketio - The client is using an unsupported version of the Socket.IO or Engine.IO protocols](https://github.com/miguelgrinberg/python-socketio/issues/578). – terrymorse Jan 09 '21 at 21:38
  • Okay @terrymorse, turns out there was a version of JavaScript Socket.IO embedded in my HTML, version 2.0.4. I explain in [my answer here](https://stackoverflow.com/a/65649075/11163122), which explicitly discusses the solution. Thanks again for your patience, and for linking that issue. Knowing what I know now, your answer makes much more sense. – Intrastellar Explorer Jan 10 '21 at 00:41
1

I have found a solution. This is what the head of my index.html file looks like:

<title>Chat Room</title>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/1.4.8/socket.io.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
</head>

I found this script from some tutorial on youtube. I am programming on Pycharm and when i left clicked the link in this line: <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script> it opened a popup asking me if i wanted to install the package.

Hope this works for you to see the javaScript part of the code you can look at my question: How do i properly install flask-socketIO?

0

Alright, thanks to the previous two answers to this question, I finally figured out how to identify the version of JavaScript Socket.IO.

The underlying reason I couldn't figure out faster was:

  • I inherited this code base, so I didn't really what it imported where
  • I don't really know Flask

The version of JavaScript Socket.IO was called out within layout.html in the templates directory (see Flask docs here). Within the <head> element, the socket.io.js script is embedded:

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.0.4/socket.io.js"></script>

It clearly calls out the version of JavaScript Socket.IO to be 2.0.4.

So, per Flask-SocketIO's version compatibility table and this comment on a Flask-SocketIO issue, I will now just pin Flask-SocketIO in my package's requirements like so: Flask-SocketIO>=4.3.2,<5.

Since this answer is to my use case, and not generic, I will not be accepting as the answer.

Intrastellar Explorer
  • 3,005
  • 9
  • 52
  • 119
0

You can see the following chart to understand the version compatibility:

enter image description here

Recently I have tried and tested following versions in my mac and they are totally compatible with each other:

Backend:

python-engineio==4.1.0 
python-socketio==5.2.1 
Flask==1.1.2 
Flask-SocketIO==5.0.1

Frontend:

socket.io-client="^3.0.0"
Saket Suraj
  • 165
  • 1
  • 2
  • 10