From b39ba0533a0acf327ccaf4e60696240f4693bb50 Mon Sep 17 00:00:00 2001 From: Ben Busby Date: Wed, 22 Mar 2023 12:29:05 -0600 Subject: [PATCH] Suppress spurious warnings from bs4 More MarkupResemblesLocatorWarning warnings have been appearing. This seems to be caused by parsing HTML content that contains a URL. This new change suppresses the warning at the root level of the app before any content has been parsed, so this error shouldn't appear again. Fixes #968 --- app/__init__.py | 7 ++++++- app/utils/results.py | 5 +---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/app/__init__.py b/app/__init__.py index a65be03..d3cf3ce 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -4,14 +4,16 @@ from app.utils.session import generate_key from app.utils.bangs import gen_bangs_json from app.utils.misc import gen_file_hash, read_config_bool from base64 import b64encode +from bs4 import MarkupResemblesLocatorWarning from datetime import datetime, timedelta +from dotenv import load_dotenv from flask import Flask import json import logging.config import os from stem import Signal import threading -from dotenv import load_dotenv +import warnings from werkzeug.middleware.proxy_fix import ProxyFix @@ -174,6 +176,9 @@ app.jinja_env.globals.update( # Attempt to acquire tor identity, to determine if Tor config is available send_tor_signal(Signal.HEARTBEAT) +# Suppress spurious warnings from BeautifulSoup +warnings.simplefilter('ignore', MarkupResemblesLocatorWarning) + from app import routes # noqa # Disable logging from imported modules diff --git a/app/utils/results.py b/app/utils/results.py index 82c4d2b..a3d74a4 100644 --- a/app/utils/results.py +++ b/app/utils/results.py @@ -1,6 +1,6 @@ from app.models.config import Config from app.models.endpoint import Endpoint -from bs4 import BeautifulSoup, NavigableString, MarkupResemblesLocatorWarning +from bs4 import BeautifulSoup, NavigableString import copy from flask import current_app import html @@ -10,9 +10,6 @@ from urllib.parse import parse_qs import re import warnings -# Suppress incorrect warnings from bs4 related to parsing HTML content -warnings.filterwarnings('ignore', category=MarkupResemblesLocatorWarning) - SKIP_ARGS = ['ref_src', 'utm'] SKIP_PREFIX = ['//www.', '//mobile.', '//m.', 'www.', 'mobile.', 'm.'] GOOG_STATIC = 'www.gstatic.com'