From cede43de4bcf5e6061f1c53894b9a58d5215b480 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Fri, 1 Apr 2022 16:06:44 +0200 Subject: [PATCH] add option to use http basic auth to retrieve formdatas (#63469) --- .../management/commands/notify_sectors.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/passerelle_montpellier_encombrants/management/commands/notify_sectors.py b/passerelle_montpellier_encombrants/management/commands/notify_sectors.py index 2264ca5..25ff7cc 100644 --- a/passerelle_montpellier_encombrants/management/commands/notify_sectors.py +++ b/passerelle_montpellier_encombrants/management/commands/notify_sectors.py @@ -16,9 +16,13 @@ class Command(BaseCommand): api_user = getattr(settings, 'ENCOMBRANTS_API_USER') secret = getattr(settings, 'ENCOMBRANTS_API_SECRET') orig = getattr(settings, 'ENCOMBRANTS_API_ORIG') - if sign: + use_http_auth = getattr(settings, 'ENCOMBRANTS_API_HTTP_AUTH', False) + kwargs = {} + if use_http_auth: + kwargs['auth'] = (settings.ENCOMBRANTS_API_HTTP_USERNAME, settings.ENCOMBRANTS_API_HTTP_PASSWORD) + elif sign: url = sign_url(url + '&email=' + urllib.quote(api_user), secret) + '&orig=' + urllib.quote(orig) - return requests.get(url, headers={'Accept': 'application/json'}) + return requests.get(url, headers={'Accept': 'application/json'}, *kwargs) def handle(self, *args, **kwargs): if not getattr(settings, 'ENCOMBRANTS_FORM_URL', None):