From c2696592b10b8421678cd5e227cb82b85110f567 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juhani=20Krekel=C3=A4?= Date: Sun, 10 Sep 2023 13:15:18 +0300 Subject: [PATCH] Use custom User-Agent and send Accept* headers for better compatibility --- botcmd.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/botcmd.py b/botcmd.py index 7730b37..5471582 100644 --- a/botcmd.py +++ b/botcmd.py @@ -138,7 +138,14 @@ def handle_message(*, prefix, message, nick, channel, irc): try: try: - with urllib.request.urlopen(url, timeout = 5) as response: + headers = { + 'User-Agent': 'Cockatric4 (like Lynx)', + 'Accept': '*/*', + 'Accept-Language': 'en,*;q=0.1', + 'Accept-Charset': 'utf-8', + } + request = urllib.request.Request(url, headers = headers) + with urllib.request.urlopen(request, timeout = 5) as response: if response.info().get_content_type() == 'text/html': # First 4KiB of a page should be enough for any # Turns out it's not, so download 64KiB