diff --git a/api/utils/web_utils.py b/api/utils/web_utils.py index 23d2421862..e7c1b48f51 100644 --- a/api/utils/web_utils.py +++ b/api/utils/web_utils.py @@ -173,6 +173,9 @@ def __get_pdf_from_html(path: str, timeout: int, install_driver: bool, print_opt try: WebDriverWait(driver, timeout).until(staleness_of(driver.find_element(by=By.TAG_NAME, value="html"))) except TimeoutException: + pass + + try: calculated_print_options = { "landscape": False, "displayHeaderFooter": False, @@ -181,8 +184,9 @@ def __get_pdf_from_html(path: str, timeout: int, install_driver: bool, print_opt } calculated_print_options.update(print_options) result = __send_devtools(driver, "Page.printToPDF", calculated_print_options) - driver.quit() return base64.b64decode(result["data"]) + finally: + driver.quit() def is_valid_url(url: str) -> bool: