From 4c02405c203c1799152fcb67eeba7eba56bec539 Mon Sep 17 00:00:00 2001 From: Brendan Howell Date: Sat, 2 May 2020 08:59:52 +0200 Subject: [PATCH] catching SSL errors --- screenless/bureau/bureau.py | 10 ++++++++-- screenless/bureau/mailroom/mailroom.py | 4 ++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/screenless/bureau/bureau.py b/screenless/bureau/bureau.py index 1f9611f..008ff71 100644 --- a/screenless/bureau/bureau.py +++ b/screenless/bureau/bureau.py @@ -384,8 +384,14 @@ class Bureau(object): pdfpath = tempfile.mkstemp(".pdf")[1] self.log.debug("rendering to: " + pdfpath) - weasyprint.HTML(string=templ.render_unicode(**kwargs)).write_pdf(pdfpath) - subprocess.call("lpr -o sides=two-sided-long-edge -o InputSlot=Upper " + pdfpath, shell=True) + # use an URL fetcher that waits 30s instead of 10s + def slowfetch(url, timeout=30, ssl_context=None): + return weasyprint.default_url_fetcher(url, 30, ssl_context) + + weasyprint.HTML(url_fetcher=slowfetch, + string=templ.render_unicode(**kwargs)).write_pdf(pdfpath) + subprocess.call("lpr -o sides=two-sided-long-edge -o InputSlot=Upper " + + pdfpath, shell=True) # TODO: make this asynchronous def print_small(self, text, cut=True): diff --git a/screenless/bureau/mailroom/mailroom.py b/screenless/bureau/mailroom/mailroom.py index 99b229b..3086775 100644 --- a/screenless/bureau/mailroom/mailroom.py +++ b/screenless/bureau/mailroom/mailroom.py @@ -10,7 +10,7 @@ import string import imapclient import kode256 -from ssl import SSLSyscallError +from ssl import SSLSysCallError from bureau import Bureau, add_command, add_api @@ -76,7 +76,7 @@ class MailRoom(Bureau): """ try: self.imapserv.select_folder("INBOX") - except (self.imapserv.AbortError, SSLSyscallError) as err: + except (self.imapserv.AbortError, SSLSysCallError) as err: self.log.debug("reconnecting after imap connection error: ", err) self.imapserv.logout() self.imapserv = imapclient.IMAPClient(self.host, use_uid=True, ssl=self.imap_ssl)