From 4e4404ff79863b7ca4b2f1cf0c03cd454fc018ef Mon Sep 17 00:00:00 2001 From: Joao620 Date: Wed, 1 May 2024 19:44:41 -0300 Subject: [PATCH] infer the url protocol --- app/index.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/app/index.py b/app/index.py index 8f15d85..c82c934 100644 --- a/app/index.py +++ b/app/index.py @@ -12,10 +12,15 @@ def bypass_paywall(url): """ Bypass paywall for a given url """ - response = requests.get(url, headers=googlebot_headers) - response.encoding = response.apparent_encoding - return response.text - + if url.startswith("http"): + response = requests.get(url, headers=googlebot_headers) + response.encoding = response.apparent_encoding + return response.text + + try: + return bypass_paywall("https://" + url) + except requests.exceptions.RequestException as e: + return bypass_paywall("http://" + url) @app.route("/") def main_page():