Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions source/updateCheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
import threading
import time
import pickle
import urllib
# #9818: one must import at least urllib.request in Python 3 in order to use full urllib functionality.
import urllib.request
import urllib.parse
import tempfile
import hashlib
import ctypes.wintypes
Expand Down Expand Up @@ -119,16 +121,16 @@ def checkForUpdate(auto=False):
"outputBrailleTable":config.conf['braille']['translationTable'] if brailleDisplayClass else None,
}
params.update(extraParams)
url = "%s?%s" % (CHECK_URL, urllib.urlencode(params))
url = "%s?%s" % (CHECK_URL, urllib.parse.urlencode(params))
try:
res = urllib.urlopen(url)
res = urllib.request.urlopen(url)
except IOError as e:
if isinstance(e.strerror, ssl.SSLError) and e.strerror.reason == "CERTIFICATE_VERIFY_FAILED":
# #4803: Windows fetches trusted root certificates on demand.
# Python doesn't trigger this fetch (PythonIssue:20916), so try it ourselves
_updateWindowsRootCertificates()
# and then retry the update check.
res = urllib.urlopen(url)
res = urllib.request.urlopen(url)
else:
raise
if res.code != 200:
Expand Down Expand Up @@ -610,13 +612,12 @@ def _bg(self):
self._guiExec(self._downloadSuccess)

def _download(self, url):
remote = urllib.urlopen(url)
if remote.code != 200:
raise RuntimeError("Download failed with code %d" % remote.code)
# #2352: Some security scanners such as Eset NOD32 HTTP Scanner
# cause huge read delays while downloading.
# Therefore, set a higher timeout.
remote.fp._sock.settimeout(120)
remote = urllib.request.urlopen(url, timeout=120)
if remote.code != 200:
raise RuntimeError("Download failed with code %d" % remote.code)
size = int(remote.headers["content-length"])
with open(self.destPath, "wb") as local:
if self.fileHash:
Expand Down Expand Up @@ -807,7 +808,7 @@ def _updateWindowsRootCertificates():
crypt = ctypes.windll.crypt32
# Get the server certificate.
sslCont = ssl._create_unverified_context()
u = urllib.urlopen("https://www.nvaccess.org/nvdaUpdateCheck", context=sslCont)
u = urllib.request.urlopen("https://www.nvaccess.org/nvdaUpdateCheck", context=sslCont)
cert = u.fp._sock.getpeercert(True)
u.close()
# Convert to a form usable by Windows.
Expand Down