Skip to content

Commit

Permalink
test web servers: fix ssl error
Browse files Browse the repository at this point in the history
urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:600)>
  • Loading branch information
treemo committed May 11, 2015
1 parent d59eaaf commit 0a19fe2
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions tests/web/test_servers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from os import path
from socket import gaierror
import ssl

from circuits.web import Controller
from circuits import handler, Component
Expand All @@ -12,6 +13,7 @@
from .helpers import urlopen, URLError

CERTFILE = path.join(path.dirname(__file__), "cert.pem")
SSL_CONTEXT = ssl._create_unverified_context() # self signed cert


class BaseRoot(Component):
Expand Down Expand Up @@ -90,7 +92,7 @@ def test_secure_server(manager, watcher):
Root().register(server)

try:
f = urlopen(server.http.base)
f = urlopen(server.http.base, context=SSL_CONTEXT)
except URLError as e:
if isinstance(e.reason, gaierror):
f = urlopen("http://127.0.0.1:9000")
Expand Down Expand Up @@ -142,7 +144,7 @@ def test_multi_servers(manager, watcher):
s = f.read()
assert s == b"Hello World!"

f = urlopen(secure_server.http.base)
f = urlopen(secure_server.http.base, context=SSL_CONTEXT)
s = f.read()
assert s == b"Hello World!"

Expand Down

0 comments on commit 0a19fe2

Please sign in to comment.