Repository: oppia/oppia

Issue:
SSL727 problem during installation 
Hi! I am trying to set up Oppia for the first time. I have already use the correct version of python and tried PYTHONHTTPSVERIFY=0. However, when I run python -m scripts.start, it still shows that IOError: [Errno socket error] [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:727). What could I do about that? Thank you!


Discussion:
Hi @ziqixu2000 did this issue get resolved for you?

Resolving patch:
diff --git a/python_utils.py b/python_utils.py
--- a/python_utils.py
+++ b/python_utils.py
@@ -30,6 +30,10 @@
 _YAML_PATH = os.path.join(os.getcwd(), '..', 'oppia_tools', 'pyyaml-5.1.2')
 sys.path.insert(0, _YAML_PATH)
 
+_CERTIFI_PATH = os.path.join(
+    os.getcwd(), '..', 'oppia_tools', 'certifi-2020.12.5')
+sys.path.insert(0, _CERTIFI_PATH)
+
 import yaml  # isort:skip  pylint: disable=wrong-import-position, wrong-import-order
 
 import builtins  # isort:skip  pylint: disable=wrong-import-position, wrong-import-order
@@ -38,6 +42,9 @@
 import past.utils  # isort:skip  pylint: disable=wrong-import-position, wrong-import-order
 import six  # isort:skip  pylint: disable=wrong-import-position, wrong-import-order
 
+import certifi  # isort:skip  pylint: disable=wrong-import-position, wrong-import-order
+import ssl  # isort:skip  pylint: disable=wrong-import-position, wrong-import-order
+
 
 BASESTRING = past.builtins.basestring
 INPUT = builtins.input
@@ -297,6 +304,7 @@ def url_retrieve(source_url, filename=None):
     Returns:
         urlretrieve. The 'urlretrieve' object.
     """
+    context = ssl.create_default_context(cafile=certifi.where())
     try:
         import urllib
 
@@ -306,11 +314,13 @@ def url_retrieve(source_url, filename=None):
             'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) '
             'Gecko/20100101 Firefox/47.0'
         )
-        return urllib.urlretrieve(source_url, filename=filename)
+        return urllib.urlretrieve(
+            source_url, filename=filename, context=context)
     except ImportError:
         import urllib.request
 
-        return urllib.request.urlretrieve(source_url, filename=filename)
+        return urllib.request.urlretrieve(
+            source_url, filename=filename, context=context)
 
 
 def url_open(source_url):
@@ -324,14 +334,15 @@ def url_open(source_url):
     Returns:
         urlopen. The 'urlopen' object.
     """
+    context = ssl.create_default_context(cafile=certifi.where())
     try:
         import urllib2
 
-        return urllib2.urlopen(source_url)
+        return urllib2.urlopen(source_url, context=context)
     except ImportError:
         import urllib.request
 
-        return urllib.request.urlopen(source_url)
+        return urllib.request.urlopen(source_url, context=context)
 
 
 def url_request(source_url, data, headers):
diff --git a/scripts/install_third_party_libs.py b/scripts/install_third_party_libs.py
--- a/scripts/install_third_party_libs.py
+++ b/scripts/install_third_party_libs.py
@@ -32,6 +32,8 @@
     ('pyyaml', '5.1.2', os.path.join(TOOLS_DIR, 'pyyaml-5.1.2')),
     ('future', '0.18.2', os.path.join('third_party', 'python_libs')),
     ('six', '1.15.0', os.path.join('third_party', 'python_libs')),
+    ('certifi', '2020.12.5', os.path.join(
+        TOOLS_DIR, 'certifi-2020.12.5')),
 ]
 
 for package_name, version_number, target_path in PREREQUISITES:


Test patch:
diff --git a/scripts/script_import_test.py b/scripts/script_import_test.py
--- a/scripts/script_import_test.py
+++ b/scripts/script_import_test.py
@@ -74,4 +74,8 @@ def mock_exists(unused_path):
                 'six==1.15.0', '--target',
                 'third_party/python_libs',
                 '--user', '--prefix=', '--system',
+                sys.executable, '-m', 'pip', 'install',
+                'certifi==2020.12.5', '--target',
+                '../oppia_tools/certifi-2020.12.5',
+                '--user', '--prefix=', '--system',
             ])