Skip to content

Commit c8526d7

Browse files
authored
Add user agent to Wikipedia API requests
1 parent 58fb7d6 commit c8526d7

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

bot/exts/utilities/wikipedia.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@
3535
"{description}\n"
3636
)
3737

38+
WIKI_HEADERS = {
39+
"User-Agent": "SirLancebot/0.0 (https://github.com/python-discord; [email protected]) aiohttp/0.0"
40+
}
41+
3842

3943
class WikipediaSearch(commands.Cog):
4044
"""Get info from wikipedia."""
@@ -45,7 +49,7 @@ def __init__(self, bot: Bot):
4549
async def wiki_request(self, channel: TextChannel, search: str) -> list[str]:
4650
"""Search wikipedia search string and return formatted first 10 pages found."""
4751
params = WIKI_PARAMS | {"srlimit": 10, "srsearch": search}
48-
async with self.bot.http_session.get(url=SEARCH_API, params=params) as resp:
52+
async with self.bot.http_session.get(url=SEARCH_API, params=params, headers=WIKI_HEADERS) as resp:
4953
if resp.status != 200:
5054
log.info(f"Unexpected response `{resp.status}` while searching wikipedia for `{search}`")
5155
raise APIError("Wikipedia API", resp.status)

0 commit comments

Comments
 (0)