Skip to content

Set proxy settings from envars #377

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
13 changes: 10 additions & 3 deletions util/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import magic
import zlib
import lzma
import os
from datetime import datetime, timezone
from enum import Enum
from hashlib import md5, sha1, sha256, sha512
Expand All @@ -28,17 +29,23 @@
from time import time
from tqdm import tqdm

from patchman.signals import error_message, info_message, debug_message

from django.utils.timezone import make_aware
from django.utils.dateparse import parse_datetime
from django.conf import settings

from patchman.signals import error_message, info_message, debug_message

pbar = None
verbose = None
Checksum = Enum('Checksum', 'md5 sha sha1 sha256 sha512')

http_proxy = os.getenv('http_proxy')
https_proxy = os.getenv('https_proxy')
proxies = {
'http': http_proxy,
'https': https_proxy,
}


def get_verbosity():
""" Get the global verbosity level
Expand Down Expand Up @@ -113,7 +120,7 @@ def get_url(url, headers={}, params={}):
response = None
try:
debug_message.send(sender=None, text=f'Trying {url} headers:{headers} params:{params}')
response = requests.get(url, headers=headers, params=params, stream=True, timeout=30)
response = requests.get(url, headers=headers, params=params, stream=True, proxies=proxies, timeout=30)
debug_message.send(sender=None, text=f'{response.status_code}: {response.headers}')
if response.status_code in [403, 404]:
return response
Expand Down