title: ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749)
body: <p>I am trying to use the betbrain.py from Github (<a href="https://github.com/gto76/betbrain-scraper" rel="noreferrer">https://github.com/gto76/betbrain-scraper</a>) that has the following code:</p>
  <pre><code>#!/usr/bin/python3
  #
  # Usage: betbrain.py [URL or FILE] [OUTPUT-FILE]
  # Scrapes odds from passed betbrain page and writes them to
  # stdout, or file if specified.
  
  import os
  import sys
  import urllib.request
  
  
  from bs4 import BeautifulSoup
  from http.cookiejar import CookieJar
  
  import parser_betbrain
  import printer
  
  DEFAULT_URL = 'https://www.betbrain.com/football/england/premier-league/#!/matches/'
  
  
  # If no arguments are present, it parses the default page.
  # Argument can be an URL or a local file.
  def main():
    html = getHtml(sys.argv)
    soup = BeautifulSoup(html, &quot;html.parser&quot;)
    matches = parser_betbrain.getMatches(soup)
    string = printer.matchesToString(matches)
    output(string, sys.argv)
  
  def getHtml(argv):
    if len(argv) &lt;= 1:
      return scrape(DEFAULT_URL)
    elif argv[1].startswith(&quot;http&quot;):
      return scrape(argv[1])
    else:
      return readFile(argv[1])
  
  # Returns html file located at URL.
  def scrape(url):
    cj = CookieJar()
    opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj))
    try:
      return opener.open(url)
    except ValueError:
      error(&quot;Invalid URL: &quot; + url)
  
  def readFile(path):
    try:
      return open(path, encoding='utf8')
    except IOError:
      error(&quot;Invalid input filename: &quot; + path)
  
  def output(string, argv):
    if len(argv) &lt;= 2:
      print(string)
    else:
      writeFile(argv[2], string)
  
  def writeFile(path, string):
    try:  
      fo = open(path, &quot;w&quot;, encoding='utf8')
      fo.write(string);
      fo.close()
    except IOError:
      error(&quot;Invalid output filename: &quot; + path)
  
  def error(msg):
    msg = os.path.basename(__file__)+&quot;: &quot;+msg
    print(msg, file=sys.stderr)
    sys.exit(1)
  
  if __name__ == '__main__':
    main()
  </code></pre>
  <p><strong>However when run it comes back with this error</strong></p>
  <pre><code>Traceback (most recent call last):
    File &quot;/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py&quot;, line 1318, in do_open
      encode_chunked=req.has_header('Transfer-encoding'))
    File &quot;/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py&quot;, line 1239, in request
      self._send_request(method, url, body, headers, encode_chunked)
    File &quot;/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py&quot;, line 1285, in _send_request
      self.endheaders(body, encode_chunked=encode_chunked)
    File &quot;/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py&quot;, line 1234, in endheaders
      self._send_output(message_body, encode_chunked=encode_chunked)
    File &quot;/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py&quot;, line 1026, in _send_output
      self.send(msg)
    File &quot;/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py&quot;, line 964, in send
      self.connect()
    File &quot;/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py&quot;, line 1400, in connect
      server_hostname=server_hostname)
    File &quot;/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py&quot;, line 401, in wrap_socket
      _context=self, _session=session)
    File &quot;/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py&quot;, line 808, in __init__
      self.do_handshake()
    File &quot;/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py&quot;, line 1061, in do_handshake
      self._sslobj.do_handshake()
    File &quot;/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py&quot;, line 683, in do_handshake
      self._sslobj.do_handshake()
  ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749)
  
  During handling of the above exception, another exception occurred:
  
  Traceback (most recent call last):
    File &quot;/Users/Daniel/Desktop/betbrain-scraper-master 2/betbrain.py&quot;, line 71, in &lt;module&gt;
      main()
    File &quot;/Users/Daniel/Desktop/betbrain-scraper-master 2/betbrain.py&quot;, line 22, in main
      html = getHtml(sys.argv)
    File &quot;/Users/Daniel/Desktop/betbrain-scraper-master 2/betbrain.py&quot;, line 30, in getHtml
      return scrape(DEFAULT_URL)
    File &quot;/Users/Daniel/Desktop/betbrain-scraper-master 2/betbrain.py&quot;, line 41, in scrape
      return opener.open(url)
    File &quot;/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py&quot;, line 526, in open
      response = self._open(req, data)
    File &quot;/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py&quot;, line 544, in _open
      '_open', req)
    File &quot;/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py&quot;, line 504, in _call_chain
      result = func(*args)
    File &quot;/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py&quot;, line 1361, in https_open
      context=self._context, check_hostname=self._check_hostname)
    File &quot;/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py&quot;, line 1320, in do_open
      raise URLError(err)
  urllib.error.URLError: &lt;urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749)&gt;
  </code></pre>
  <p><strong>How can I fix this problem? I am running Python 3.6.0 on MacOS 10.12.1</strong></p>