Search code examples
pythonflaskwebserverflask-socketioreplit

flasksocketio OSError: proxy not found


I am using Replit to run the code. I am a beginner in useing flask and socketio. Whenver I import flask_socketio(line 2) is makes the OSError mentioned in the title.

Here is my server code:

from flask import *
from flask_socketio import *

app = Flask(__name__, template_folder = "templates", static_folder='static')
socketio = SocketIO(app)

@app.route("/")
def main_page():
  return render_template("main.html")

@socketio.on("buttonPressed")
def handleRequest():
  print("Request Recieved!")
  return ("", 204)

if __name__ == "__main__":
  app.run(host = "0.0.0.0", port = 2345)

Here is the website:

<html>
  <body>
    <h1>Request Testing</h1>
    <button onclick="testButton()">Test</button>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/4.0.1/socket.io.js" integrity="sha512-q/dWJ3kcmjBLU4Qc47E4A9kTB4m3wuTY7vkFJDTZKjTs8jhyGQnaUrxa0Ytd0ssMZhbNua9hE+E7Qv1j+DyZwA==" crossorigin="anonymous"></script>
    <script>
      var socket = io();
      
      function testButton() {
        socket.emit("buttonPressed");
      }
    </script>
  </body>
</html>

It is supposed to make a website that when you click the button is will send a message to the server telling it the button was clicked. Then the server prints a message saying the button was pressed. I have tried many things like installing librarys people have said you need(I have forgoton what most of them are). I have tried many articles and have no idea what im doing wrong. I am using pip install so it is possible that I have installed it wrong but as far as I'm aware that the proper way to do it.

Here is the error log if that helps:

Traceback (most recent call last):
  File "main.py", line 2, in <module>
    from flask_socketio import *
  File "/home/runner/Website-Testing/venv/lib/python3.8/site-packages/flask_socketio/__init__.py", line 9, in <module>
    from socketio import socketio_manage  # noqa: F401
  File "/home/runner/Website-Testing/venv/lib/python3.8/site-packages/socketio/__init__.py", line 9, in <module>
    from .zmq_manager import ZmqManager
  File "/home/runner/Website-Testing/venv/lib/python3.8/site-packages/socketio/zmq_manager.py", line 5, in <module>
    import eventlet.green.zmq as zmq
  File "/home/runner/Website-Testing/venv/lib/python3.8/site-packages/eventlet/__init__.py", line 17, in <module>
    from eventlet import convenience
  File "/home/runner/Website-Testing/venv/lib/python3.8/site-packages/eventlet/convenience.py", line 7, in <module>
    from eventlet.green import socket
  File "/home/runner/Website-Testing/venv/lib/python3.8/site-packages/eventlet/green/socket.py", line 21, in <module>
    from eventlet.support import greendns
  File "/home/runner/Website-Testing/venv/lib/python3.8/site-packages/eventlet/support/greendns.py", line 71, in <module>
    setattr(dns.rdtypes.IN, pkg, import_patched('dns.rdtypes.IN.' + pkg))
  File "/home/runner/Website-Testing/venv/lib/python3.8/site-packages/eventlet/support/greendns.py", line 61, in import_patched
    return patcher.import_patched(module_name, **modules)
  File "/home/runner/Website-Testing/venv/lib/python3.8/site-packages/eventlet/patcher.py", line 129, in import_patched
    return inject(
  File "/home/runner/Website-Testing/venv/lib/python3.8/site-packages/eventlet/patcher.py", line 106, in inject
    module = __import__(module_name, {}, {}, module_name.split('.')[:-1])
  File "/home/runner/Website-Testing/venv/lib/python3.8/site-packages/dns/rdtypes/IN/WKS.py", line 25, in <module>
    _proto_tcp = socket.getprotobyname('tcp')
OSError: protocol not found

Solution

  • Are you using eventlet for anything? Try uninstalling it if not. Based from your stack trace it is getting imported and used.