mirror of
https://github.com/Hopiu/linkchecker.git
synced 2026-04-29 10:34:42 +00:00
Improve error handling and debugging for login form
This commit is contained in:
parent
9a33c2a659
commit
a51f02cf66
2 changed files with 7 additions and 1 deletions
|
|
@ -87,16 +87,22 @@ class Aggregate (object):
|
|||
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"]
|
||||
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
|
||||
for key, value in self.config["loginextrafields"].items():
|
||||
form.data[key] = value
|
||||
formurl = parse.urljoin(url, form.url)
|
||||
log.debug(LOG_CHECK, "Posting login data to %s", formurl)
|
||||
response = session.post(formurl, data=form.data)
|
||||
response.raise_for_status()
|
||||
self.cookies = session.cookies
|
||||
if len(self.cookies) == 0:
|
||||
raise LinkCheckerError("No cookies set by login URL %s" % url)
|
||||
|
|
|
|||
|
|
@ -54,5 +54,5 @@ def search_form(content, cgiuser, cgipassword):
|
|||
return form
|
||||
|
||||
# not found
|
||||
log.debug(LOG_CHECK, "Form with fields %s not found", ",".join(cginames))
|
||||
log.warn(LOG_CHECK, "Form with fields %s not found", ",".join(cginames))
|
||||
return None
|
||||
|
|
|
|||
Loading…
Reference in a new issue