more verbose error messages on https failures

This commit is contained in:
Alexander Bersenev
2018-12-30 14:25:17 +05:00
parent bd8e0f935d
commit cb10355681

View File

@@ -1022,26 +1022,19 @@ async def update_middle_proxy_info():
HTTP_REQ_TEMPLATE = "\r\n".join(["GET %s HTTP/1.1", "Host: core.telegram.org", HTTP_REQ_TEMPLATE = "\r\n".join(["GET %s HTTP/1.1", "Host: core.telegram.org",
"Connection: close"]) + "\r\n\r\n" "Connection: close"]) + "\r\n\r\n"
try: reader, writer = await asyncio.open_connection(url_data.netloc, SSL_PORT, ssl=True)
reader, writer = await asyncio.open_connection(url_data.netloc, SSL_PORT, ssl=True) req = HTTP_REQ_TEMPLATE % urllib.parse.quote(url_data.path)
req = HTTP_REQ_TEMPLATE % urllib.parse.quote(url_data.path) writer.write(req.encode("utf8"))
writer.write(req.encode("utf8")) data = await reader.read()
data = await reader.read() writer.close()
writer.close()
headers, body = data.split(b"\r\n\r\n", 1) headers, body = data.split(b"\r\n\r\n", 1)
return body return body
except Exception:
return b""
async def get_new_proxies(url): async def get_new_proxies(url):
PROXY_REGEXP = re.compile(r"proxy_for\s+(-?\d+)\s+(.+):(\d+)\s*;") PROXY_REGEXP = re.compile(r"proxy_for\s+(-?\d+)\s+(.+):(\d+)\s*;")
ans = {} ans = {}
try: body = await make_https_req(url)
body = await make_https_req(url)
except Exception:
return ans
fields = PROXY_REGEXP.findall(body.decode("utf8")) fields = PROXY_REGEXP.findall(body.decode("utf8"))
if fields: if fields:
@@ -1069,16 +1062,16 @@ async def update_middle_proxy_info():
if not v4_proxies: if not v4_proxies:
raise Exception("no proxy data") raise Exception("no proxy data")
TG_MIDDLE_PROXIES_V4 = v4_proxies TG_MIDDLE_PROXIES_V4 = v4_proxies
except Exception: except Exception as E:
print_err("Error updating middle proxy list") print_err("Error updating middle proxy list:", E)
try: try:
v6_proxies = await get_new_proxies(PROXY_INFO_ADDR_V6) v6_proxies = await get_new_proxies(PROXY_INFO_ADDR_V6)
if not v6_proxies: if not v6_proxies:
raise Exception("no proxy data (ipv6)") raise Exception("no proxy data (ipv6)")
TG_MIDDLE_PROXIES_V6 = v6_proxies TG_MIDDLE_PROXIES_V6 = v6_proxies
except Exception: except Exception as E:
print_err("Error updating middle proxy list for IPv6") print_err("Error updating middle proxy list for IPv6:", E)
try: try:
secret = await make_https_req(PROXY_SECRET_ADDR) secret = await make_https_req(PROXY_SECRET_ADDR)
@@ -1087,8 +1080,8 @@ async def update_middle_proxy_info():
if secret != PROXY_SECRET: if secret != PROXY_SECRET:
PROXY_SECRET = secret PROXY_SECRET = secret
print_err("Middle proxy secret updated") print_err("Middle proxy secret updated")
except Exception: except Exception as E:
print_err("Error updating middle proxy secret, using old") print_err("Error updating middle proxy secret, using old", E)
await asyncio.sleep(PROXY_INFO_UPDATE_PERIOD) await asyncio.sleep(PROXY_INFO_UPDATE_PERIOD)