check for empty proxy

This commit is contained in:
Roy Olav Purser 2021-05-12 12:22:01 +02:00
parent 3ccbef047e
commit 462a3dbbc5
Signed by: roypur
GPG Key ID: E14D26A036F21656

View File

@ -200,6 +200,7 @@ class MainHandler(tornado.web.RequestHandler):
streams = proxy.stream.streams(src) streams = proxy.stream.streams(src)
for key in reversed(streams): for key in reversed(streams):
stream = streams.get(key) stream = streams.get(key)
print(stream)
if hasattr(stream, "url"): if hasattr(stream, "url"):
upstream = stream.url upstream = stream.url
break break
@ -220,11 +221,14 @@ class MainHandler(tornado.web.RequestHandler):
ldata["proxy"] = proxy.proxy ldata["proxy"] = proxy.proxy
ldata["proxied"] = isinstance(proxy.proxy, str) ldata["proxied"] = isinstance(proxy.proxy, str)
links = [ldata] links = [ldata]
resp = requests.post(proxy_server, json=links) try:
if isinstance(resp.text, str): resp = requests.post(proxy_server, json=links)
new_links = json.loads(resp.text) if isinstance(resp.text, str):
if isinstance(new_links, list) and len(new_links) == 1: new_links = json.loads(resp.text)
upstream = new_links.pop() if isinstance(new_links, list) and len(new_links) == 1:
upstream = new_links.pop()
except Exception as e:
print(e)
if data is None: if data is None:
self.redirect(upstream, status=303) self.redirect(upstream, status=303)
else: else: