From 5b445c7219c3088ee486c9cd70adfa9c52dfa1f8 Mon Sep 17 00:00:00 2001 From: Serghei Mihai Date: Mon, 4 Dec 2017 10:04:16 +0100 Subject: [PATCH] misc: add support for REQUEST_PROXIES (#20378) --- corbo/models.py | 4 ++-- corbo/settings.py | 5 +++++ corbo/utils.py | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/corbo/models.py b/corbo/models.py index c519c38..f15a810 100644 --- a/corbo/models.py +++ b/corbo/models.py @@ -42,7 +42,7 @@ class Category(models.Model): super(Category, self).save(*args, **kwargs) if not self.rss_feed_url: return - feed_response = requests.get(self.rss_feed_url) + feed_response = requests.get(self.rss_feed_url, proxies=settings.REQUESTS_PROXIES) if feed_response.ok: content = feedparser.parse(feed_response.content) for entry in content.get('entries', []): @@ -81,7 +81,7 @@ class Announce(models.Model): if img.attrib['src'].startswith('/'): continue image_name = os.path.basename(img.attrib['src']) - r = requests.get(img.attrib['src']) + r = requests.get(img.attrib['src'], proxies=settings.REQUESTS_PROXIES) if not r.ok: continue new_content = r.content diff --git a/corbo/settings.py b/corbo/settings.py index 62edfe8..29f740d 100644 --- a/corbo/settings.py +++ b/corbo/settings.py @@ -168,6 +168,11 @@ SMS_GATEWAY_URL = None # sms expeditor SMS_EXPEDITOR = 'Corbo' +# proxies argument passed to all python-request methods +# (see http://docs.python-requests.org/en/master/user/advanced/#proxies) +REQUESTS_PROXIES = None + + local_settings_file = os.environ.get('CORBO_SETTINGS_FILE', os.path.join(os.path.dirname(__file__), 'local_settings.py')) if os.path.exists(local_settings_file): diff --git a/corbo/utils.py b/corbo/utils.py index 3c15f04..5e5f0d0 100644 --- a/corbo/utils.py +++ b/corbo/utils.py @@ -89,7 +89,7 @@ def send_sms(content, destinations): 'message': etree.tostring(html_content, method='text'), 'from': settings.SMS_EXPEDITOR} try: - response = requests.post(settings.SMS_GATEWAY_URL, json=data) + response = requests.post(settings.SMS_GATEWAY_URL, json=data, proxies=settings.REQUESTS_PROXIES) response.raise_for_status() if not response.json()['err']: # if no error returned by SMS gateway presume the that content -- 2.15.1