-
-
Notifications
You must be signed in to change notification settings - Fork 491
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 needs an argument #33771
Comments
comment:1
and
|
comment:2
apparently adding internet to --optional= shows that all context=SSLContext() should be replaced with context=ssl.create_default_context() |
Attachment: 33771.patch.gz |
comment:3
I tested 33771.patch only on python-3.10.4 |
comment:4
thanks are you sure that this does not work in previous Python versions ? please make a branch |
comment:5
works at least in Python 3.8.10 and also in python 3.5.2 |
Changed branch from u/gh-sheerluck/create_default_context to none |
comment:8
diff --git a/src/sage/arith/misc.py b/src/sage/arith/misc.py
index 9966d0b857..7e78b8a449 100644
--- a/src/sage/arith/misc.py
+++ b/src/sage/arith/misc.py
@@ -2033,7 +2033,7 @@ def xkcd(n=""):
import contextlib
import json
from sage.misc.html import html
- from ssl import SSLContext
+ from ssl import create_default_context as SSLContext
from urllib.request import urlopen
from urllib.error import HTTPError, URLError
diff --git a/src/sage/combinat/designs/covering_design.py b/src/sage/combinat/designs/covering_design.py
index a1959604a1..f6f6a6097c 100644
--- a/src/sage/combinat/designs/covering_design.py
+++ b/src/sage/combinat/designs/covering_design.py
@@ -46,7 +46,7 @@ Classes and methods
# ****************************************************************************
from urllib.request import urlopen
-from ssl import SSLContext
+from ssl import create_default_context as SSLContext
from sage.misc.sage_eval import sage_eval
from sage.structure.sage_object import SageObject
diff --git a/src/sage/databases/oeis.py b/src/sage/databases/oeis.py
index 00cbb30e6d..a551b3f102 100644
--- a/src/sage/databases/oeis.py
+++ b/src/sage/databases/oeis.py
@@ -160,7 +160,7 @@ Classes and methods
# ****************************************************************************
from urllib.request import urlopen
from urllib.parse import urlencode
-from ssl import SSLContext
+from ssl import create_default_context as SSLContext
from sage.structure.sage_object import SageObject
from sage.structure.unique_representation import UniqueRepresentation
diff --git a/src/sage/features/internet.py b/src/sage/features/internet.py
index 5c6a077bcb..85b087cf18 100644
--- a/src/sage/features/internet.py
+++ b/src/sage/features/internet.py
@@ -40,7 +40,7 @@ class Internet(Feature):
"""
import urllib.error
from urllib.request import Request, urlopen
- from ssl import SSLContext
+ from ssl import create_default_context as SSLContext
req = Request("https://www.sagemath.org", headers={"User-Agent": "sage-doctest"})
try:
diff --git a/src/sage/graphs/isgci.py b/src/sage/graphs/isgci.py
index 99f90f7617..f97a070a5b 100644
--- a/src/sage/graphs/isgci.py
+++ b/src/sage/graphs/isgci.py
@@ -400,7 +400,7 @@ from sage.env import GRAPHS_DATA_DIR
import os
import zipfile
from urllib.request import urlopen
-from ssl import SSLContext
+from ssl import create_default_context as SSLContext
#*****************************************************************************
diff --git a/src/sage/interfaces/mathematica.py b/src/sage/interfaces/mathematica.py
index 83c90418c4..6620d40c80 100644
--- a/src/sage/interfaces/mathematica.py
+++ b/src/sage/interfaces/mathematica.py
@@ -1140,7 +1140,7 @@ def request_wolfram_alpha(input, verbose=False):
from urllib.request import Request, build_opener, HTTPCookieProcessor, HTTPSHandler
import json
from http.cookiejar import CookieJar
- from ssl import SSLContext
+ from ssl import create_default_context as SSLContext
# we need cookies for this...
cj = CookieJar()
diff --git a/src/sage/misc/messaging.py b/src/sage/misc/messaging.py
index 1a4b248cf2..cf0ad289c8 100644
--- a/src/sage/misc/messaging.py
+++ b/src/sage/misc/messaging.py
@@ -14,7 +14,7 @@ AUTHORS:
import http.client as httplib
from urllib.parse import urlencode
-from ssl import SSLContext
+from ssl import create_default_context as SSLContext
pushover_defaults = {"token": "Eql67F14ohOZJ0AtEBJJU7FiLAk8wK"}
diff --git a/src/sage/misc/package.py b/src/sage/misc/package.py
index 1ca56fbd5c..30b17c97be 100644
--- a/src/sage/misc/package.py
+++ b/src/sage/misc/package.py
@@ -51,7 +51,7 @@ import sys
from pathlib import Path
from urllib.request import urlopen
from urllib.error import URLError
-from ssl import SSLContext
+from ssl import create_default_context as SSLContext
DEFAULT_PYPI = 'https://pypi.org/pypi'
diff --git a/src/sage/misc/remote_file.py b/src/sage/misc/remote_file.py
index 092640cc9e..479480831b 100644
--- a/src/sage/misc/remote_file.py
+++ b/src/sage/misc/remote_file.py
@@ -3,7 +3,7 @@
import os
from urllib.request import Request, urlopen
-from ssl import SSLContext
+from ssl import create_default_context as SSLContext
def get_remote_file(filename, verbose=True):
--
2.35.1
|
comment:9
yes, looks better. Does it work ? |
comment:10
for python-3.10.4 -- yes :) |
comment:11
You shouldn't give a name of the ssl library for another object of the same library, this will be very confusing. I would suggest to just import create_default_context as is. |
comment:12
Replying to @sagetrac-tmonteil:
How about this then: diff --git a/src/sage/arith/misc.py b/src/sage/arith/misc.py
index 9966d0b857..abfb4ce047 100644
--- a/src/sage/arith/misc.py
+++ b/src/sage/arith/misc.py
@@ -2033,7 +2033,7 @@ def xkcd(n=""):
import contextlib
import json
from sage.misc.html import html
- from ssl import SSLContext
+ import ssl
from urllib.request import urlopen
from urllib.error import HTTPError, URLError
@@ -2046,7 +2046,8 @@ def xkcd(n=""):
url = "https://xkcd.com/{}/info.0.json".format(n)
try:
- with contextlib.closing(urlopen(url, context=SSLContext())) as f:
+ default_ctx = ssl.create_default_context()
+ with contextlib.closing(urlopen(url, context=default_ctx)) as f:
data = f.read()
except HTTPError as error:
if error.getcode() == 400: # this error occurs when asking for a non valid comic number
diff --git a/src/sage/combinat/designs/covering_design.py b/src/sage/combinat/designs/covering_design.py
index a1959604a1..5eeb07e7e2 100644
--- a/src/sage/combinat/designs/covering_design.py
+++ b/src/sage/combinat/designs/covering_design.py
@@ -46,7 +46,7 @@ Classes and methods
# ****************************************************************************
from urllib.request import urlopen
-from ssl import SSLContext
+import ssl
from sage.misc.sage_eval import sage_eval
from sage.structure.sage_object import SageObject
@@ -529,7 +529,8 @@ def best_known_covering_design_www(v, k, t, verbose=False):
if verbose:
print("Looking up the bounds at %s" % url)
- f = urlopen(url, context=SSLContext())
+ default_ctx = ssl.create_default_context()
+ f = urlopen(url, context=default_ctx)
try:
s = bytes_to_str(f.read())
finally:
diff --git a/src/sage/databases/oeis.py b/src/sage/databases/oeis.py
index 00cbb30e6d..13e82707ee 100644
--- a/src/sage/databases/oeis.py
+++ b/src/sage/databases/oeis.py
@@ -160,7 +160,6 @@ Classes and methods
# ****************************************************************************
from urllib.request import urlopen
from urllib.parse import urlencode
-from ssl import SSLContext
from sage.structure.sage_object import SageObject
from sage.structure.unique_representation import UniqueRepresentation
@@ -176,6 +175,7 @@ from sage.repl.preparse import preparse
from collections import defaultdict
import re
+import ssl
oeis_url = 'https://oeis.org/'
@@ -200,7 +200,8 @@ def _fetch(url):
"""
try:
verbose("Fetching URL %s ..." % url, caller_name='OEIS')
- f = urlopen(url, context=SSLContext())
+ default_ctx = ssl.create_default_context()
+ f = urlopen(url, context=default_ctx)
result = f.read()
f.close()
return bytes_to_str(result)
diff --git a/src/sage/features/internet.py b/src/sage/features/internet.py
index 5c6a077bcb..794edc11f3 100644
--- a/src/sage/features/internet.py
+++ b/src/sage/features/internet.py
@@ -38,13 +38,14 @@ class Internet(Feature):
sage: Internet()._is_present() # random, optional - internet
FeatureTestResult('internet', True)
"""
+ import ssl
import urllib.error
from urllib.request import Request, urlopen
- from ssl import SSLContext
req = Request("https://www.sagemath.org", headers={"User-Agent": "sage-doctest"})
try:
- urlopen(req, timeout=1, context=SSLContext())
+ default_ctx = ssl.create_default_context()
+ urlopen(req, timeout=1, context=default_ctx)
return FeatureTestResult(self, True)
except urllib.error.URLError:
return FeatureTestResult(self, False)
diff --git a/src/sage/graphs/isgci.py b/src/sage/graphs/isgci.py
index 99f90f7617..e9705cf488 100644
--- a/src/sage/graphs/isgci.py
+++ b/src/sage/graphs/isgci.py
@@ -398,9 +398,9 @@ from sage.misc.unknown import Unknown
from sage.env import GRAPHS_DATA_DIR
import os
+import ssl
import zipfile
from urllib.request import urlopen
-from ssl import SSLContext
#*****************************************************************************
@@ -828,7 +828,8 @@ class GraphClasses(UniqueRepresentation):
sage: graph_classes._download_db() # Not tested -- requires internet
"""
from sage.misc.misc import SAGE_TMP
- u = urlopen('https://www.graphclasses.org/data.zip', context=SSLContext())
+ default_ctx = ssl.create_default_context()
+ u = urlopen('https://www.graphclasses.org/data.zip', context=default_ctx)
localFile = open(os.path.join(SAGE_TMP, 'isgci.zip'), 'w')
localFile.write(u.read())
localFile.close()
diff --git a/src/sage/interfaces/mathematica.py b/src/sage/interfaces/mathematica.py
index 83c90418c4..e77366c49a 100644
--- a/src/sage/interfaces/mathematica.py
+++ b/src/sage/interfaces/mathematica.py
@@ -1136,15 +1136,16 @@ def request_wolfram_alpha(input, verbose=False):
'timing',
'version']
"""
+ from http.cookiejar import CookieJar
from urllib.parse import urlencode
from urllib.request import Request, build_opener, HTTPCookieProcessor, HTTPSHandler
import json
- from http.cookiejar import CookieJar
- from ssl import SSLContext
+ import ssl
# we need cookies for this...
cj = CookieJar()
- opener = build_opener(HTTPCookieProcessor(cj), HTTPSHandler(context=SSLContext()))
+ default_ctx = ssl.create_default_context()
+ opener = build_opener(HTTPCookieProcessor(cj), HTTPSHandler(context=default_ctx))
# build initial query for code
req = Request("https://www.wolframalpha.com/input/api/v1/code")
resp = opener.open(req)
diff --git a/src/sage/misc/messaging.py b/src/sage/misc/messaging.py
index 1a4b248cf2..eda7087416 100644
--- a/src/sage/misc/messaging.py
+++ b/src/sage/misc/messaging.py
@@ -12,9 +12,10 @@ AUTHORS:
- Martin Albrecht (2012) - initial implementation
"""
+import ssl
import http.client as httplib
from urllib.parse import urlencode
-from ssl import SSLContext
+
pushover_defaults = {"token": "Eql67F14ohOZJ0AtEBJJU7FiLAk8wK"}
@@ -77,7 +78,8 @@ def pushover(message, **kwds):
request.update(pushover_defaults)
request.update(kwds)
- conn = httplib.HTTPSConnection("api.pushover.net:443", context=SSLContext())
+ default_ctx = ssl.create_default_context()
+ conn = httplib.HTTPSConnection("api.pushover.net:443", context=default_ctx)
conn.request("POST", "/1/messages.json",
urlencode(request),
{"Content-type": "application/x-www-form-urlencoded"})
diff --git a/src/sage/misc/package.py b/src/sage/misc/package.py
index 1ca56fbd5c..a2f1dcd938 100644
--- a/src/sage/misc/package.py
+++ b/src/sage/misc/package.py
@@ -47,11 +47,11 @@ import sage.env
import json
import os
import subprocess
+import ssl
import sys
from pathlib import Path
from urllib.request import urlopen
from urllib.error import URLError
-from ssl import SSLContext
DEFAULT_PYPI = 'https://pypi.org/pypi'
@@ -110,7 +110,8 @@ def pip_remote_version(pkg, pypi_url=DEFAULT_PYPI, ignore_URLError=False):
url = '{pypi_url}/{pkg}/json'.format(pypi_url=pypi_url, pkg=pkg)
try:
- f = urlopen(url, context=SSLContext())
+ default_ctx = ssl.create_default_context()
+ f = urlopen(url, context=default_ctx)
text = f.read()
f.close()
except URLError:
diff --git a/src/sage/misc/remote_file.py b/src/sage/misc/remote_file.py
index 092640cc9e..296974ba5c 100644
--- a/src/sage/misc/remote_file.py
+++ b/src/sage/misc/remote_file.py
@@ -2,8 +2,8 @@
import os
+import ssl
from urllib.request import Request, urlopen
-from ssl import SSLContext
def get_remote_file(filename, verbose=True):
@@ -43,7 +43,8 @@ def get_remote_file(filename, verbose=True):
if verbose:
print("Loading started")
- content = urlopen(req, timeout=1, context=SSLContext())
+ default_ctx = ssl.create_default_context()
+ content = urlopen(req, timeout=1, context=default_ctx)
with open(temp_name, 'wb') as f:
f.write(content.read())
|
Commit: |
comment:13
here is a branch, please review New commits:
|
Author: Frédéric Chapoton |
Branch: u/chapoton/33771 |
comment:14
simple one, I think |
comment:15
Looks good to me, let us wait for the patchbots to confirm. |
Reviewer: Thierry Monteil |
comment:16
Since patchbots are not running internet doctests by default, i ran them by hand. |
Changed branch from u/chapoton/33771 to |
with python 3.10, one sees a deprecation
CC: @tscrim @slel @kliem @kwankyu
Component: interfaces
Author: Frédéric Chapoton
Branch/Commit:
93e7f60
Reviewer: Thierry Monteil
Issue created by migration from https://trac.sagemath.org/ticket/33771
The text was updated successfully, but these errors were encountered: