Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Importing eventlet returns "socket.error: protocol not found" #370

Closed
minglethepringle opened this issue Jan 2, 2017 · 3 comments
Closed

Comments

@minglethepringle
Copy link

minglethepringle commented Jan 2, 2017

I installed Eventlet via pip: pip install eventlet. I'm running GNURoot Debian on Android.

I then went into the Python shell and did import eventlet. There, it gave me an error message:

root@localhost:~/flaskprojects/testing# python
iPython 2.7.13 (default, Jan  1 2017, 23:23:59)
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import eventlet
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/eventlet/__init__.py", line 15, in <module>
    from eventlet import convenience
  File "/usr/local/lib/python2.7/dist-packages/eventlet/convenience.py", line 6, in <module>
    from eventlet.green import socket
  File "/usr/local/lib/python2.7/dist-packages/eventlet/green/socket.py", line 28, in <module>
    from eventlet.support import greendns
  File "/usr/local/lib/python2.7/dist-packages/eventlet/support/greendns.py", line 69, in <module>
    setattr(dns.rdtypes.IN, pkg, import_patched('dns.rdtypes.IN.' + pkg))
  File "/usr/local/lib/python2.7/dist-packages/eventlet/support/greendns.py", line 59, in import_patched
    return patcher.import_patched(module_name, **modules)
  File "/usr/local/lib/python2.7/dist-packages/eventlet/patcher.py", line 119, in import_patched
    *additional_modules + tuple(kw_additional_modules.items()))
  File "/usr/local/lib/python2.7/dist-packages/eventlet/patcher.py", line 93, in inject
    module = __import__(module_name, {}, {}, module_name.split('.')[:-1])
  File "/usr/local/lib/python2.7/dist-packages/eventlet/support/dns/rdtypes/IN/WKS.py", line 23, in <module>
    _proto_tcp = socket.getprotobyname('tcp')
socket.error: protocol not found
>>>

I see socket, so it might be worthwhile mentioning that I'm using eventlet for a Flask + Socket.IO program.

Code:

from flask import Flask, request, render_template
from flask_socketio import SocketIO
from flask_cors import CORS, cross_origin
app = Flask(__name__)
app.config['SECRET_KEY']='secret!'
socketio = SocketIO(app)
STATUS = "i am an empty string"

import eventlet
eventlet.monkey_patch()

@socketio.on('message')
def handle_message(message):
    print(message)
    global STATUS
    if message == "READY_TO_RECEIVE":
        STATUS = "READY"
    else:
        STATUS = "ERROR"
    print(STATUS)

@socketio.on('status')
def handle_message_status(status):
    print(status)

@app.route("/login", methods=["GET", "POST"])
@cross_origin()
def login():
    if request.method == "POST":
        print("THIS IS POST REQUEST!")
        data = request.data
        print(data)
        print(STATUS)

        #if STATUS == "READY":
        socketio.emit("message", data)

        return 'success'

    else:
        return "THIS IS GET REQUEST!"

@app.route("/")
def index():
    return "<html><body><h1>Hellooooooooooo</h1></body></html>"

@app.route("/user/<username>")
def showusername(username):
    return "Welcome back, %s" % username

@app.route("/post/<int:post_id>")
def showpost(post_id):
    return "Post #%d" % post_id



if __name__ == '__main__':
    CORS(app)
    socketio.run(app, host='0.0.0.0', debug = False, use_reloader=False)
@temoto
Copy link
Member

temoto commented Jan 2, 2017

Does it work without eventlet installed? python -c "import socket ; socket.getprotobyname('tcp')"

@temoto
Copy link
Member

temoto commented Jan 2, 2017

If not, it's a platform configuration error, see https://stackoverflow.com/questions/40184788/protocol-not-found-socket-getprotobyname

TL;DR: you should have /etc/protocols contain line tcp 6 TCP.

@minglethepringle
Copy link
Author

@temoto Thanks, the command on that link worked!

srstsavage added a commit to srstsavage/micromamba-docker that referenced this issue Sep 12, 2023
netbase is a tiny (~30kB installed) package providing some core TCP/IP
files. It's somehow not included in debian:bookworm-slim which
can lead to some unexpected errors when trying to use micromamba-docker
based images (example: eventlet crashes with `socket.error: protocol not found`
if netbase is not installed.

eventlet/eventlet#370
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants