From c44201d1ffc48ff00077f437f5910292ecece384 Mon Sep 17 00:00:00 2001 From: gitolicious <26963495+gitolicious@users.noreply.github.com> Date: Thu, 17 Jun 2021 23:25:06 +0200 Subject: [PATCH] add Cloudflare-specific error message on login request --- doctoshotgun.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/doctoshotgun.py b/doctoshotgun.py index 5dea369..08e4baf 100755 --- a/doctoshotgun.py +++ b/doctoshotgun.py @@ -198,7 +198,14 @@ def __init__(self, *args, **kwargs): self.patient = None def do_login(self): - self.open(self.BASEURL + '/sessions/new') + try: + self.open(self.BASEURL + '/sessions/new') + except ServerError as e: + if e.response.status_code in [503] \ + and 'text/html' in e.response.headers['Content-Type'] \ + and 'cloudflare' in e.response.text: + log('Request blocked by CloudFlare', color='red') + raise try: self.login.go(json={'kind': 'patient', 'username': self.username,