replace urllib with requests

This commit is contained in:
GeorgianaElena
2019-05-24 14:37:42 +03:00
parent a54f104d1d
commit cfb3ec43cd
4 changed files with 23 additions and 14 deletions

View File

@@ -8,10 +8,9 @@ import secrets
import subprocess
import sys
import time
from urllib.error import HTTPError
from urllib.request import urlopen, URLError
import pluggy
import requests
from tljh import (
apt,
@@ -293,20 +292,20 @@ def ensure_jupyterhub_running(times=20):
for i in range(times):
try:
logger.info('Waiting for JupyterHub to come up ({}/{} tries)'.format(i + 1, times))
urlopen('http://127.0.0.1')
requests.get('http://127.0.0.1')
return
except HTTPError as h:
if h.code in [404, 502, 503]:
except requests.HTTPError as h:
if h.response.status_code in [404, 502, 503]:
# May be transient
time.sleep(1)
continue
# Everything else should immediately abort
raise
except URLError as e:
if isinstance(e.reason, ConnectionRefusedError):
except requests.ConnectionError:
# Hub isn't up yet, sleep & loop
time.sleep(1)
continue
except Exception:
# Everything else should immediately abort
raise