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

SSLContext.set_npn_protocols broken in Python 3.10 #308

Closed
diabonas opened this issue Dec 13, 2021 · 4 comments · Fixed by #309
Closed

SSLContext.set_npn_protocols broken in Python 3.10 #308

diabonas opened this issue Dec 13, 2021 · 4 comments · Fixed by #309

Comments

@diabonas
Copy link
Contributor

When trying to load the weechat-matrix script with Python 3.10, it fails with the following error:

19:23 python: stdout/stderr (matrix): Traceback (most recent call last):
19:23 python: stdout/stderr (matrix): File "/home/jonas/.local/share/weechat/python/autoload/weechat-matrix.py", line 708, in <module>
19:23 python: stdout/stderr (matrix): create_default_server(G.CONFIG)
19:23 python: stdout/stderr (matrix): File "/usr/lib/python3.10/site-packages/matrix/server.py", line 1989, in create_default_server
19:23 python: stdout/stderr (matrix): server = MatrixServer("matrix_org", config_file._ptr)
19:23 python: stdout/stderr (matrix): File "/usr/lib/python3.10/site-packages/matrix/server.py", line 307, in __init__
19:23 python: stdout/stderr (matrix): self.ssl_context.set_npn_protocols(["h2", "http/1.1"])
19:23 python: stdout/stderr (matrix): File "/usr/lib/python3.10/ssl.py", line 546, in set_npn_protocols
19:23 python: stdout/stderr (matrix): self._set_npn_protocols(protos)
19:23 python: stdout/stderr (matrix): AttributeError: 'SSLContext' object has no attribute '_set_npn_protocols'. Did you mean: 'set_npn_protocols'?

This is due to an upstream issue in Python 3.10 with SSLContext.set_npn_protocols, reported upstream as bpo-46067.

Since the function is deprecated in Python 3.10 anyway, the broken function can simply be removed, cf. e.g. the patch I use for the Arch Linux package:

From 4e585d5f4628e6fbeba9ec4560b440d731e076f5 Mon Sep 17 00:00:00 2001
From: Jonas Witschel <diabonas@archlinux.org>
Date: Sat, 11 Dec 2021 19:47:16 +0100
Subject: [PATCH] server: remove set_npn_protocols()

This function is deprecated in favour of set_alpn_protocols(), which is already
called, and is currently broken in Python 3.10, so remove it altogether.
---
 matrix/server.py | 5 -----
 1 file changed, 5 deletions(-)

diff --git a/matrix/server.py b/matrix/server.py
index dda861e..0f34c1e 100644
--- a/matrix/server.py
+++ b/matrix/server.py
@@ -303,11 +303,6 @@ class MatrixServer(object):
         # Enable http2 negotiation on the ssl context.
         self.ssl_context.set_alpn_protocols(["h2", "http/1.1"])
 
-        try:
-            self.ssl_context.set_npn_protocols(["h2", "http/1.1"])
-        except NotImplementedError:
-            pass
-
         self.address = None
         self.homeserver = None
         self.client = None  # type: Optional[HttpClient]
-- 
2.34.1
@ghost
Copy link

ghost commented Dec 13, 2021

Hello,
Is there a fix ?

@diabonas
Copy link
Contributor Author

For upstream Python 3.10 there is no fix as far as I am aware, but you can work around the issue in weechat-matrix by applying the patch I included above.

@poljar
Copy link
Owner

poljar commented Dec 13, 2021

When trying to load the weechat-matrix script with Python 3.10, it fails with the following error:

19:23 python: stdout/stderr (matrix): Traceback (most recent call last):
19:23 python: stdout/stderr (matrix): File "/home/jonas/.local/share/weechat/python/autoload/weechat-matrix.py", line 708, in <module>
19:23 python: stdout/stderr (matrix): create_default_server(G.CONFIG)
19:23 python: stdout/stderr (matrix): File "/usr/lib/python3.10/site-packages/matrix/server.py", line 1989, in create_default_server
19:23 python: stdout/stderr (matrix): server = MatrixServer("matrix_org", config_file._ptr)
19:23 python: stdout/stderr (matrix): File "/usr/lib/python3.10/site-packages/matrix/server.py", line 307, in __init__
19:23 python: stdout/stderr (matrix): self.ssl_context.set_npn_protocols(["h2", "http/1.1"])
19:23 python: stdout/stderr (matrix): File "/usr/lib/python3.10/ssl.py", line 546, in set_npn_protocols
19:23 python: stdout/stderr (matrix): self._set_npn_protocols(protos)
19:23 python: stdout/stderr (matrix): AttributeError: 'SSLContext' object has no attribute '_set_npn_protocols'. Did you mean: 'set_npn_protocols'?

This is due to an upstream issue in Python 3.10 with SSLContext.set_npn_protocols, reported upstream as bpo-46067.

Since the function is deprecated in Python 3.10 anyway, the broken function can simply be removed, cf. e.g. the patch I use for the Arch Linux package:

From 4e585d5f4628e6fbeba9ec4560b440d731e076f5 Mon Sep 17 00:00:00 2001
From: Jonas Witschel <diabonas@archlinux.org>
Date: Sat, 11 Dec 2021 19:47:16 +0100
Subject: [PATCH] server: remove set_npn_protocols()

This function is deprecated in favour of set_alpn_protocols(), which is already
called, and is currently broken in Python 3.10, so remove it altogether.
---
 matrix/server.py | 5 -----
 1 file changed, 5 deletions(-)

diff --git a/matrix/server.py b/matrix/server.py
index dda861e..0f34c1e 100644
--- a/matrix/server.py
+++ b/matrix/server.py
@@ -303,11 +303,6 @@ class MatrixServer(object):
         # Enable http2 negotiation on the ssl context.
         self.ssl_context.set_alpn_protocols(["h2", "http/1.1"])
 
-        try:
-            self.ssl_context.set_npn_protocols(["h2", "http/1.1"])
-        except NotImplementedError:
-            pass
-
         self.address = None
         self.homeserver = None
         self.client = None  # type: Optional[HttpClient]
-- 
2.34.1

Hi, could you turn this into a pull request?

@diabonas
Copy link
Contributor Author

Sure, done: #309

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

Successfully merging a pull request may close this issue.

2 participants