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

python3.7 and eventlet0.25 exception #1011

Closed
zhenglq opened this issue Jun 25, 2019 · 8 comments
Closed

python3.7 and eventlet0.25 exception #1011

zhenglq opened this issue Jun 25, 2019 · 8 comments
Labels

Comments

@zhenglq
Copy link

zhenglq commented Jun 25, 2019

Hi! miguel

official doc recommend eventlet, but I get into trobute.

environment

python version: 3.7.3
eventlet: 0.25.0
flask-socketio:  4.1.0

exception:

File "/Users/zlq/work/aes/gitlab/rainbow_circle/venv/lib/python3.7/site-packages/requests/api.py", line 60, in request
return session.request(method=method, url=url, **kwargs)
File "/Users/zlq/work/aes/gitlab/rainbow_circle/venv/lib/python3.7/site-packages/requests/sessions.py", line 533, in request
resp = self.send(prep, **send_kwargs)
File "/Users/zlq/work/aes/gitlab/rainbow_circle/venv/lib/python3.7/site-packages/requests/sessions.py", line 646, in send
r = adapter.send(request, **kwargs)
File "/Users/zlq/work/aes/gitlab/rainbow_circle/venv/lib/python3.7/site-packages/requests/adapters.py", line 449, in send
timeout=timeout
File "/Users/zlq/work/aes/gitlab/rainbow_circle/venv/lib/python3.7/site-packages/urllib3/connectionpool.py", line 603, in urlopen
chunked=chunked)
File "/Users/zlq/work/aes/gitlab/rainbow_circle/venv/lib/python3.7/site-packages/urllib3/connectionpool.py", line 344, in _make_request
self._validate_conn(conn)
File "/Users/zlq/work/aes/gitlab/rainbow_circle/venv/lib/python3.7/site-packages/urllib3/connectionpool.py", line 843, in validate_conn
conn.connect()
File "/Users/zlq/work/aes/gitlab/rainbow_circle/venv/lib/python3.7/site-packages/urllib3/connection.py", line 350, in connect
ssl_context=context)
File "/Users/zlq/work/aes/gitlab/rainbow_circle/venv/lib/python3.7/site-packages/urllib3/util/ssl
.py", line 355, in ssl_wrap_socket
return context.wrap_socket(sock, server_hostname=server_hostname)
File "/Users/zlq/work/aes/gitlab/rainbow_circle/venv/lib/python3.7/site-packages/eventlet/green/ssl.py", line 438, in wrap_socket
return GreenSSLSocket(sock, *a, _context=self, **kw)
File "/Users/zlq/work/aes/gitlab/rainbow_circle/venv/lib/python3.7/site-packages/eventlet/green/ssl.py", line 76, in new
*args, **kw
TypeError: wrap_socket() got an unexpected keyword argument '_context'

eventlet/eventlet#526 (comment)

Is there any good way? or switch to gevent

@zhenglq zhenglq changed the title python3.7 and eventlet0.25 cexception python3.7 and eventlet0.25 exception Jun 25, 2019
@miguelgrinberg
Copy link
Owner

In general I've seen lots of problems when trying to work with eventlet and SSL together. If at all possible, I recommend that you terminate the SSL connection before the request reaches the server. I use nginx as reverse proxy for SSL termination.

This particular error has already been filed as an eventlet bug: eventlet/eventlet#526.

@zhenglq
Copy link
Author

zhenglq commented Jun 26, 2019

Thank you for your response! I will be try.

@zhenglq zhenglq closed this as completed Jun 27, 2019
@techouse
Copy link

techouse commented Jul 6, 2019

Indeed the issue is with eventlet.

I decorated my Flask's password authentication with a Google reCAPTCHA decorator which basically sends a some data to Google's servers over SSL.

This is the decorator:

def verify_recaptcha(f):
    @wraps(f)
    def decorated_function(*args, **kwargs):
        g.recaptcha_valid = None

        if (
            request.method == "POST"
            and current_app.config["RECAPTCHA_SITE_KEY"]
            and current_app.config["RECAPTCHA_SECRET_KEY"]
        ):
            data = request.get_json() if request.get_json() else request.data
            recaptcha_token = data.get("recaptcha_token")
            if recaptcha_token:
                r = requests.post(
                    "https://www.google.com/recaptcha/api/siteverify",
                    data={
                        "secret": current_app.config["RECAPTCHA_SECRET_KEY"],
                        "response": recaptcha_token,
                        "remoteip": request.access_route[0],
                    },
                )
                result = r.json()
                g.recaptcha_valid = result.get("success") or False
            else:
                g.recaptcha_valid = False

        return f(*args, **kwargs)

    return decorated_function

As soon as I switched over to gevent it works as expected.

@obrua
Copy link

obrua commented Jul 21, 2019

I have the same problem.

python version: 3.7.1
eventlet: 0.25.0
flask-socketio: 4.1.0
flask-mail: 0.9.1

when executing flask-mail mail.send(Message)
exception:

File "C:\GitHub*.com\back-end*_celery.py", line 16, in
mail.send(msg)
File "c:\github*.com\back-end.venv\lib\site-packages\flask_mail.py", line 491, in send
with self.connect() as connection:
File "c:\github*.com\back-end.venv\lib\site-packages\flask_mail.py", line 144, in enter
self.host = self.configure_host()
File "c:\github*.com\back-end.venv\lib\site-packages\flask_mail.py", line 156, in configure_host
host = smtplib.SMTP_SSL(self.mail.server, self.mail.port)
File "C:\Users\andy9\AppData\Local\Programs\Python\Python37\Lib\smtplib.py", line 1031, in init
source_address)
File "C:\Users\andy9\AppData\Local\Programs\Python\Python37\Lib\smtplib.py", line 251, in init
(code, msg) = self.connect(host, port)
File "C:\Users\andy9\AppData\Local\Programs\Python\Python37\Lib\smtplib.py", line 336, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "C:\Users\andy9\AppData\Local\Programs\Python\Python37\Lib\smtplib.py", line 1039, in _get_socket
server_hostname=self._host)
File "c:\github*.com\back-end.venv\lib\site-packages\eventlet\green\ssl.py", line 440, in wrap_socket
return GreenSSLSocket(sock, *a, _context=self, **kw)
File "c:\github*.com\back-end.venv\lib\site-packages\eventlet\green\ssl.py", line 76, in new
*args, **kw
TypeError: wrap_socket() got an unexpected keyword argument '_context'

i just del the eventlet\green\ssl.py *args, **kw , The problem is solved

    if _is_under_py_3_7:
        return super(GreenSSLSocket, cls).__new__(cls)
    else:
        if not isinstance(sock, GreenSocket):
            sock = GreenSocket(sock)
        with _original_ssl_context():
            ret = _original_wrap_socket(
                sock=sock.fd,
                keyfile=keyfile,
                certfile=certfile,
                server_side=server_side,
                cert_reqs=cert_reqs,
                ssl_version=ssl_version,
                ca_certs=ca_certs,
                do_handshake_on_connect=False,

*args, **kw
)
ret.keyfile = keyfile
ret.certfile = certfile
ret.cert_reqs = cert_reqs
ret.ssl_version = ssl_version
ret.ca_certs = ca_certs
ret.class = GreenSSLSocket
return ret

@acnebs
Copy link

acnebs commented Sep 26, 2019

Just as an FYI to anyone else -- I actually was terminating SSL at Nginx, so for a second I was confused as to why I was getting this error. But then I realized that the managed Redis db I'm using for orchestration between flask_socketio instances required connecting via SSL/TLS (digitalocean's managed Redis), which was then causing eventlet to break down.

@miguelgrinberg Do you have a recommendation for a workaround that doesn't involve just communicating with Redis unencrypted? I'm currently running Nginx for SSL termination / load-balancing multiple gunicorn processes with one eventlet worker each on my machines. Then those machines are behind another load-balancer.

@miguelgrinberg
Copy link
Owner

@acnebs I don't have any workarounds, sorry. The issue is currently being worked on, so hopefully a fix will be available soon.

@ba1dr
Copy link

ba1dr commented Jul 1, 2020

Python 3.8. The following configuration gave an issue for me.

eventlet==0.25.2
Flask-SocketIO==4.3.0
python-socketio==4.6.0
requests==2.24.0
requests-oauthlib==1.3.0

after downgrading to requests==2.23.0 it started to work!

Posting this just if someone comes here from Google (like me was).

@CesMak
Copy link

CesMak commented Jul 18, 2020

Python 3.8. The following configuration gave an issue for me.

eventlet==0.25.2
Flask-SocketIO==4.3.0
python-socketio==4.6.0
requests==2.24.0
requests-oauthlib==1.3.0

after downgrading to requests==2.23.0 it started to work!

Posting this just if someone comes here from Google (like me was).

Hm I have same dependencys except the requests I do not have at all.... Nevertheless the same error occurs for me. I also removed ssl.py and now everything works....

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

No branches or pull requests

7 participants