diff --git a/zulip_bots/zulip_bots/bots/google_search/google_search.py b/zulip_bots/zulip_bots/bots/google_search/google_search.py index dc981d5e..007ffc02 100644 --- a/zulip_bots/zulip_bots/bots/google_search/google_search.py +++ b/zulip_bots/zulip_bots/bots/google_search/google_search.py @@ -3,7 +3,7 @@ import logging from typing import Dict, List import requests -from bs4 import BeautifulSoup +from bs4 import BeautifulSoup, Tag from zulip_bots.lib import BotHandler @@ -16,7 +16,9 @@ def google_search(keywords: str) -> List[Dict[str, str]]: soup = BeautifulSoup(page.text, "lxml") # Gets all search URLs - anchors = soup.find(id="search").findAll("a") + search = soup.find(id="search") + assert isinstance(search, Tag) + anchors = search.findAll("a") results = [] for a in anchors: diff --git a/zulip_bots/zulip_bots/bots/google_search/test_google_search.py b/zulip_bots/zulip_bots/bots/google_search/test_google_search.py index c6f0b4e0..950188bc 100644 --- a/zulip_bots/zulip_bots/bots/google_search/test_google_search.py +++ b/zulip_bots/zulip_bots/bots/google_search/test_google_search.py @@ -32,9 +32,7 @@ class TestGoogleSearchBot(BotTestCase, DefaultTests): def test_attribute_error(self) -> None: with self.mock_http_conversation("test_attribute_error"), patch("logging.exception"): - self.verify_reply( - "test", "Error: Search failed. 'NoneType' object has no attribute 'findAll'." - ) + self.verify_reply("test", "Error: Search failed. .") # Makes sure cached results, irrelevant links, or empty results are not displayed def test_ignore_links(self) -> None: