misc: add support for REQUEST_PROXIES (#20378)

This commit is contained in:
Serghei Mihai 2017-12-04 10:04:16 +01:00
parent 894153074a
commit 5b445c7219
3 changed files with 8 additions and 3 deletions

View File

@ -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

View File

@ -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):

View File

@ -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