diff --git a/linkcheck/director/aggregator.py b/linkcheck/director/aggregator.py index 6600b3e4..c8fdb175 100644 --- a/linkcheck/director/aggregator.py +++ b/linkcheck/director/aggregator.py @@ -83,19 +83,24 @@ class Aggregate: if not url: return user, password = self.config.get_user_password(url) + if not user and not password: + raise LinkCheckerError( + "loginurl is configured but neither user nor password are set") session = requests.Session() # XXX user-agent header # XXX timeout log.debug(LOG_CHECK, "Getting login form %s", url) response = session.get(url) response.raise_for_status() - cgiuser = self.config["loginuserfield"] - cgipassword = self.config["loginpasswordfield"] + cgiuser = self.config["loginuserfield"] if user else None + cgipassword = self.config["loginpasswordfield"] if password else None form = loginformsearch.search_form(response.text, cgiuser, cgipassword) if not form: raise LinkCheckerError("Login form not found at %s" % url) - form.data[cgiuser] = user - form.data[cgipassword] = password + if user: + form.data[cgiuser] = user + if password: + form.data[cgipassword] = password for key, value in self.config["loginextrafields"].items(): form.data[key] = value formurl = parse.urljoin(url, form.url) diff --git a/linkcheck/htmlutil/loginformsearch.py b/linkcheck/htmlutil/loginformsearch.py index 0beb69e8..576bef01 100644 --- a/linkcheck/htmlutil/loginformsearch.py +++ b/linkcheck/htmlutil/loginformsearch.py @@ -41,7 +41,7 @@ def search_form(content, cgiuser, cgipassword): CGI fields. If no form is found return None. """ soup = htmlsoup.make_soup(content) - cginames = {cgiuser, cgipassword} + cginames = {cgiuser, cgipassword} - {None} for form_element in soup.find_all("form", action=True): form = Form(form_element["action"]) for input_element in form_element.find_all("input",