| 52 | |
| 53 | @classmethod |
| 54 | def get_plain(cls, url, timeout): |
| 55 | server = urlparse(url) |
| 56 | try_until = time.time() + timeout |
| 57 | while time.time() < try_until: |
| 58 | # noinspection PyBroadException |
| 59 | try: |
| 60 | c = HTTPConnection(server.hostname, server.port, timeout=timeout) |
| 61 | c.request('GET', server.path) |
| 62 | resp = c.getresponse() |
| 63 | data = resp.read() |
| 64 | c.close() |
| 65 | return data |
| 66 | except IOError: |
| 67 | log.debug("connect error:", sys.exc_info()[0]) |
| 68 | time.sleep(.1) |
| 69 | except: |
| 70 | log.error("Unexpected error:", sys.exc_info()[0]) |
| 71 | log.error("Unable to contact server after %d sec" % timeout) |
| 72 | return None |
| 73 | |
| 74 | def __init__(self, cert_path, cert=None): |
| 75 | if cert_path is not None: |